A set of functions for communicating with the OpenAI ChatGPT API in Microsoft Excel and perform various taasks. This was tested under the latest version of Microsoft Excel. Adjustments may be needed to run with older versions.
Added ChatGPTSummarize() function. Writes a short summary paragraph about the data in a selection of cells. (https://www.youtube.com/watch?v=i9MPDIbnErI)
Added ChatGPTQuerySelection() function. Allows you to ask query ChatGPT about the data in a selection of cells.
(https://www.youtube.com/watch?v=VrmhIFKKYBA)
Added a ChatGPTList() function. Pass in something you want a list of like in the video below, you can have the list output vertically and horizontally.
ChatGPTList demo:
(https://www.youtube.com/watch?v=bLxEHdxFb9k)
Added a ChatGPTQuickFill() function, you pass in the number of cells you want to look backward for on the fill (if the cells don't exist or are empty they are ignored). No prompt engineering required, the prompt is engineered automatically.
Here's a demo video of the new Quick Fill:
(https://www.youtube.com/watch?v=t9rUA67DV0E)
These instructions may only apply to recent versions of Microsoft Windows. You will need:
- Open Microsoft Excel and click on the "Developer" tab.
- Click on the "Visual Basic" button.
- In the "Microsoft Visual Basic for Applications" window, click on "Insert" and then "Module".
- Replace the existing code with the code in the "chatgpt-excel-function.vba" file.
- Replace
sk-YOUR-CHATGPT-KEY-HERE
with your own OpenAI API key.
Prompt chatGPT in a cell by typing =ChatGPT(prompt)
, where prompt
is the text you want to send to the ChatGPT API.
Quick fill cells using ChatGPT without a prompt using =ChatGPTQuickFill(optional titleCell, optional contextCell)
where title row and context row default to row 1, and column a. A prompt will be automatically generated.
Insert lists with ChatGPT using =ChatGPTList(topic, optional horizontal)
The list will be created based on the passed in topic, by default the list will be placed vertically.
Query cells with ChatGPT Using =ChatGPTQuerySelection(query, selection, optional isheader)
This allows you query a selection of cells, you can set isHeader to true and it will use the first row as topic headers. Currently this uses JSON, but that may change or have another option because of higher token count. ChatGPT though seems to work best with JSON data rather than other formats tested.
Summarize cells with ChatGPTUsing =ChatGPTSummarizeSelection(selection, optional isheader)
This allows you to summarize a selection of cells. Set isHeader true to use the first row to identify variable in the JSON that is passed to ChatGPT.
If you receive an error related to WinHttp.WinHttpRequest.5.1
, it means that the WinHttp
library is not registered on your computer. To resolve this issue, you can try re-registering the library by running the following command in an elevated command prompt:
regsvr32 %systemroot%\system32\winhttp.dll
If the error persists, you may need to reinstall the library. You can download it from the Microsoft website.
The UnescapeString
function is used to format the response from the API into a human-readable format. If you encounter any errors or unexpected output, please refer to the comments in the code for further assistance.
The authors and contributors of this program provide it as-is, without any warranties or guarantees. They cannot be held responsible for any damages resulting from the use of this program.
This program is licensed under the MIT license.
Johann Dowa (John)