Join 300,000+ professionals in our courses:
⯆ Get the files Here:

OpenAI inside Excel? How can you use an API key to connect to an AI model from Excel?
This video shows you how. You can download the files from the GitHub link above.
Wouldn’t it be great to have a search box in Excel you can use to ask any question? Like to create dummy data, create a formula or ask about the cast of the The Sopranos. And then artificial intelligence provides the information directly in Excel – without any copy and pasting!
In this video you’ll learn how to setup an API connection from Microsoft Excel to Open AI’s ChatGPT (GPT-3) by using Office Scripts.
As a bonus I’ll show you how you can parse the result if the answer from GPT-3 is in more than 1 line. This makes it easier to use the information in Excel.

🌍 My Online Courses ►

00:00 How to Connect Excel to Open AI ChatGPT
01:18 Answer Any Question in Excel
02:16 Use ChatBot to Write Excel Formulas
04:16 Analyze Financial Statements with AI GPT
05:21 Use AI to Create Dummy Data in Excel
07:26 How to Build Your Own AI ChatBot in Excel
08:54 Create Office Script to Connect to GPT-3
11:13 Wrap Up

🎬 LINKS to related videos:
How ChatGPT Can Help With Your Complex Excel Spreadsheets:

👕☕ Get the Official XelPlus MERCH:

🎓 Not sure which of my Excel courses fits best for you? Take the quiz:

📚 Excel RESOURCES I Recommend:

🎥 GEAR I use: #gear

More resources on my Amazon page:

🚩Let’s connect on social:
Instagram:
Twitter:
LinkedIn:

👉 This description contains affiliate links, which means at no additional cost to you, we will receive a small commission if you make a purchase using the links. This helps support the channel and allows us to continue to make videos like this. Thank you for your support!

#Excel #chatgpt #ai


AI can make you unbelievably more 
productive, but that productivity   Could be improved if you didn’t have to 
leave your app to go to another page.   And you’ve all seen videos where ChatGPT solves 
Excel problems, writes code, or explains code. And   To do that, we have to go to the OpenAI platform, 
ask it what we want, then copy and paste it into   Our application. So this video is not that type 
of video. This is where we’re going to bring AI   Inside our application, right? So that’s what 
I did here. I brought it inside my Excel file   So that I can ask a question in a cell and get 
the reply in the next cell. If I happen to ask   It a question like ”Give me the names of The 
Sopranos cast,” it puts it all in a single box,   And that bothered me. I want to put it in multiple 
separate rows, right, because it’s easier to take   That information and then work with it in Excel. 
Of course, we don’t want to have to do this   Manually, so I decided to build on this. Whenever 
ChatGPT’s answer is more than a single line,   We’re going to get a multiple-row version of 
it as well. You have no idea how excited I   Was when I got this code to work. I’m going to 
show you how I set it up, and the purpose of   This video is to inspire you and show you the 
possibilities that are out there. Let’s go. Okay, so over here on Excel for Desktop, I’ve 
created this simple layout, and in this box,   I can ask my question. So let’s say I’m talking 
with my colleagues, what the top 10 hip-hop   Songs of the 90s were. Okay, so then we click on 
”Ask,” and this is where my script is running.   The moment I click on this, notice on the side 
pane here, we get Script Run Status. This is   Based on Office Scripts. I’m going to show 
that to you in a second, how it works. Once   We get the answer from the AI back, we put it in 
this cell. Oh yeah, these were my party songs. Let’s do another one. Let’s say we’re discussing 
what the names of the Spice Girls members were.   Do you remember the Spice Girls? Do you know 
what they were? Let’s see if the AI knows.   Yeah, that’s them. Let’s include their 
nicknames as well because they did have   Some weird, strange nicknames like 
Scary, Bossy, Baby, oh, no Bossy. Now, let’s say I finally decide to get some 
work done, but I’m stuck. I can’t figure out   This formula that I need to put in here. So 
here’s what I want to do. I want to grab the   Total revenue from either the Health sheet 
or the Productivity sheet or the Game sheet.   I have different sheets here. They have a 
similar structure. My revenue is in column   B. What I wanted to do is write a SUM function 
here that looks into the correct sheet. So,   If this is Game, you should go to the Game sheet 
and grab the B column. If it’s Productivity,   You should go to the Productivity sheet. I 
don’t want to write an IF function because   I am going to have a lot of different 
sheets. I can’t figure out the formula,   But ask our AI. Okay, I’m just going to pin this 
in place and start with ”I need an Excel formula.   I need to get the sum of column B from different 
sheets. Now, the sheet name is in cell A2.”

Okay, so this is very specific to what I need 
and I want it to give me the formula. So,   Let’s ask our AI and see what we get. Okay, so 
we get: ”Assuming the sheet name is in cell A2,   You can use the following formula.” Well, 
this looks good. Let me just copy this,   Go to my sheet, and paste this in. Okay, it looks 
like everything is in order and I get a number.   Does it really work? Let’s sum up Game revenue. 
What’s our total? 210,616. That’s what we get,   210,616. So, if I change this to Productivity, 
162,643. Let’s just make sure that it works. Yes,   It works. It gave me the right formula. This saved me 
a lot of time of having to go through different   Websites, different forums, and blog posts. I 
got the answer that I wanted by just asking. Now, let’s say my boss asked me to analyze 
the balance sheet for BMW. So, I can find their   Balance sheet on the web here and I’ve done 
my task, I’ve analyzed it all on my own,   But I want to get a second opinion from 
the AI and see what it has to say. So,   I’m just going to copy everything, go back 
here, paste it in, and let’s just go all the   Way to the top and tell it what we want 
it to do. We want to analyze the balance   Sheet and tell us what it thinks the risks are. 
Okay, so let’s ask. Okay, so we get a response:   ”The balance sheet includes the following: 
a high level of intangible assets, which   Could be a risk if the company’s business model 
changes. The company has a large amount of debt   And the company has a large number of receivables, 
which could be a risk if the customers don’t pay.” Now, you can run this multiple times and you 
are going to get different responses. You can   Use these to cross-check with your own response, 
but of course, don’t take what the AI says as the   Truth. You are responsible to cross-check these 
and come up with your own informed decision. We can also use the AI to quickly give us 
some data we can work with. For example,   We want to get the top 10 countries by area. Let’s 
ask and see what we get. Okay, so we get our list   Here. Now, everything is inside the same cell. 
That’s where this part comes into play. So, I’ve   Updated the script so that whenever the result 
is more than one line, we get it into separate   Rows and we get it on this sheet here. This makes 
it easier for me to work with the data in Excel. If you’re for example, giving some training, and 
you want some fake data, you can ask it as well.   So, for example, we want to get sales data and 
budget data from January to December for a fake   Company. Format should be month, actual sales, 
and budget sales. Let’s ask and see what we get.   That’s our data right here. Now that we get it 
into separate cells, it’s easier to work with.   Now, you can also update the logic to account 
for the delimiter. It’s just that you can get   Different delimiters back from the AI, but if you 
have it in this format, it’s really easy to split   It into separate columns. You just have to go to 
the ”Data” tab, here, ”Text to Columns”, select   The limited, go next, and then select the type of 
the delimiter you have. So, here is a comma and a   Space, Finish, and we have our data in separate 
columns. Now, I can use this as fake data for my  

Training. If you’re a teacher, you could go with 
a prompt like this: ”Give me names of the Breaking   Bad characters, add a fake school subject and fake 
grade, and grades should be in percentage.” Click   On ”Ask”, and that’s what we get. Tuco Salamanca 
is not bad in math. Notice here, the delimiter   Is different here, but we get them into some 
separate rows, and then again, we can use Text to   Columns or Power Query or TEXTSPLIT function 
if you’d like to split this into separate columns.   So, I hope these examples give you some ideas 
on how you could use AI to speed up your work. Now, let me show you how I’ve set this up. So, 
this setup consists of two main ingredients:   One is Office Scripts. Now, Office Scripts
was first introduced for Excel on the web,   But recently, we got this Automate
tab in Excel for desktop as well. So,   This is the Office 365 version. The advantage 
is that, whenever you automate your tasks using   Office Scripts, that automation 
is going to work for Excel Desktop,   It’s going to work for Excel on the web or 
if you use Excel in Teams, it’s going to   Work in all places. The second ingredient is 
an API for GPT from OpenAI, and to get that,   You have to go to the OpenAI website, then click 
on API, set up an account if you don’t have one,   And then you can get your API key. So, if I 
go to my account here, go to your account,   And then you can generate your secret key. This is 
currently free for up to three months, depending   On your usage. After that, you’re going to need 
to upgrade. The API key you get is for GPT-3. So,   ChatGPT is a version of GPT-3. It was fine-tuned 
for conversation and dialogue. GPT-3 is broader. Now, once you have that, you can go ahead 
and check out the documentation. There are   Guides on how you can use this API, how you can 
make requests, and so on. Right, so have a read   Through this, then you get some ideas on how 
you can integrate this into your own models. Now, once you have this, you can go 
over to Excel and create a new script,   And you can also do this for Excel on the 
web if you don’t have the ”Automate” tab yet   In Excel for Desktop. The script you write 
is called ”Office Script”. Office Script   Is written in TypeScript and it’s a superset of 
JavaScript. The script is saved on my OneDrive,   You can also save it on SharePoint. So, let me 
quickly walk you through this, just so you get   An idea on how it’s built. The starting point 
of any Office Script is the ”main” function,   And here I’m using an asynchronous function. This 
allows the code to run independently of other   Code. We’re also using ”ExcelScript.Workbook”, so 
that we can communicate with the Excel objects. We   Need to provide the API keys. I’ve defined a 
constant for this. This is where you would be   Pasting it in. I’ve pasted it inside a cell in a 
sheet that I’ve hidden. Next up, I’ve defined some   More constants. So, here we have ”mytext,” this is 
cell B2. So, this is the ”Ask,” what we’re sending   To the AI. And down here is the communication 
with the model. We’re sending the text to the   AI model and then here, we’re getting the output 
back. The output is what we paste back in cell B4,  

Right here. You can use the documentation on 
OpenAI to help you set this up. And in my case,   I got stuck and I asked ChatGPT for help 
and it was able to solve the problem. So,   This part was a collaboration with ChatGPT. We 
got it to work. Then, I went on to add this part   That allows me to check whether I have more than 
one line, and if I do, it’s going to split it and   Paste it into separate cells. So, this is where 
that happens. We are using the ”Split” function.   This basically splits the string into a list of 
smaller strings and puts it inside an array. Then,   We loop through that array. For each instance, I’m 
checking whether the array length is greater than   Zero, and the reason I’m doing that is because 
sometimes the AI returns empty lines in between,   And if I don’t account for this, I end up 
having empty rows here, and I don’t want   That. I just want my rows with text to be below 
one another. OK, so that’s basically the script,   And you can build upon this as you need. I so wish 
I had this when I was starting to learn Excel.   There were times I could spend hours just getting 
my formula to work. Let me know what you think.   I personally enjoyed this experiment just to see 
the potential we could have in Excel. Who knows,   Maybe in the future, we can ask it to 
import the data from Bob, summarize it,   And then send it to the boss. Right? Something 
to look forward to. But let me know what you   Think. Comment below. I hope you enjoyed 
this video, and I’ll catch you next time.

Leave a Reply