A simple macro for communicating with the OpenAI ChatGPT API in Microsoft Word. This was tested under the latest version of Microsoft Word. Adjustments may be needed to run with older versions.
These instructions may only apply to recent versions of Microsoft Windows. You will need
- Open Microsoft Word and Click View Then Macros (or Alt-F8).
- Enter a name (should be ChatGPT or you will need to change the macro code), make sure normal.dotm is selected in the Macros In pulldown menu then click Create.
- The editor will open up, replace everything with the code in the macro.vba file.
- Replace
sk-YOUR-CHATGPT-KEY-HERE
with your own OpenAI API key. - Run the
ChatGPT
subroutine by pressing Alt-F8 and clicking run. - Enter the prompt you want to send to the ChatGPT API in the input box that appears.
- The response from the ChatGPT API will be inserted into the document where the cursor was last placed.
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