Create a powerful chatbot in Microsoft Word using ChatGPT
Easily access ChatGPT's awesome chatbot capabilies in Microsoft Word. This application captures the conversation history between a user and the chatbot. By utilizing conversation history, the chatbot can mimic an awareness of context and thus provide responses that make more sense.
add-gpt-chatbot-in-microsoft-word.mp4
- Requires an OpenAI API Key (create an account and get API Key at https://chat.openai.com)
- Requires Microsoft Windows 10/11 (https://www.microsoft.com/en-au/windows)
- Requires Microsoft Word 365 (https://www.microsoft.com/en-us)
- To start a chat, write a message anywhere in Microsoft Word
- Select your message and click the Chat Completion button in the AI Assistant tab
- Wait for the model to respond
- The chat response will appear under initial message
- Repeat the steps above to continue the chat
To chat about a new topic simply click the Chat Reset button in the AI Assistant tab
User Message #1
Who won the world series in 2020?
Chatbot Reply
The Los Angeles Dodgers won the World Series in 2020.
User Message #2
Where was it played?
Chatbot Reply
The 2020 World Series was played in Arlington, Texas at Globe Life Field, the home stadium of the Texas Rangers.
Conversation Flow
User: Who won the world series in 2020?
Chatbot: The Los Angeles Dodgers won the World Series in 2020.
User: Where was it played?
Chatbot: The 2020 World Series was played in Arlington, Texas at Globe Life Field, the home stadium of the Texas Rangers.
There are 4 basic steps in order to add a ChatGPT button into Microsoft Word:
- Enable the Developer Tab
- Import the VBA script files
- Create the Chat Completion and Chat Reset buttons
- Add your OpenAI APIKey
Each of these steps are fully outlined below.
The Developer tab isn't displayed by default, but you can add it to the ribbon.
Step 1 - On the File tab, go to Options > Customize Ribbon.
Step 2 - Under Customize the Ribbon and under Main Tabs, select the Developer check box.
The latest instructions to enable the Developer Tab from Microsoft can be found here:
https://support.microsoft.com/en-us/office/show-the-developer-tab-in-word-e356706f-1891-4bb8-8d72-f57a51146792
Step 1 - Download and Save the latest Chat.bas and ChatReset.bas file from the src/windows folder in this repository.
Keep the location of where the file is saved as you will need it later.
Step 2 - On the Developer tab, click the Visual Basic button.
Step 3 - On the File tab, go to Import File...
Step 4 - Add the two .bas files
- Select the Chat.bas file and click Open
- Select the ChatReset.bas file and click Open
Please Note: This project closely relates to two of our other projects:
- Add ChatGPT to Microsoft Word - project found here
- Create ChatGPT Images in Microsoft Word - project found here
If you have have already added one or both of these projects into Microsoft Word you can start at Step 3 of this section.
Step 1 - Add a new tab
- On the File tab, go to Options > Customize Ribbon
- Click New Tab
Step 2 - Rename the New Tab to AI Assistant
Step 3 - Rename New Group (Custom) to ChatBot
Step 4 - Select Macros in the Choose Commands from dropdown box
Step 5 - Select the Chat Macro and click Add >>
Step 6 - Rename button to Chat Completion, select a Symbol and click OK
Step 7 - Repeat Steps 5 & 6 to to create a Chat Reset button
- Ensure you select the ChatReset Macro to link to your Chat Reset button in this step
After the preceding steps have been completed the Microsoft Word screen should look like the following:
Step 1 - Open the Start menu and start typing "environment variables". When the best match appears click "Edit the system environment variables" result.
Step 2 - Click the "Environment variables" button under the "Advanced" tab.
Step 3 - Create a new user variable by clicking "New" under the "User Variables" section.
Step 4 - Type the variable name OPENAI_API_KEY in the first field and your OpenAI APIKEY in the variable value field. Then click OK.
Step 5 - IMPORTANT You must restart Windows to apply the new environment variable
Your OpenAI APIKEY key/s should be kept secure and private at all times.
Please follow the best practices guide for API security from OpenAI
https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety