Supercharge Your MS-Word With ChatGPT: An Exciting Leap Into the Future of Document Creation!
Image generated using Midjourney and Canva

Supercharge Your MS-Word With ChatGPT: An Exciting Leap Into the Future of Document Creation!

Hey there, document wizard! Want to add a futuristic twist to your Microsoft Word adventures? How about a friendly AI assistant to enhance your writing prowess? Meet ChatGPT, OpenAI's cutting-edge language model, poised to transform your Microsoft Word environment into a hub of creativity and efficiency.

First Things First: Gear Up

Before we embark on this exciting journey, let's ensure you've got the essentials:

  1. An OpenAI API Key. Don't have one? No worries. Just sign up here and get your key.
  2. A system with Microsoft Windows 10 or 11 and a working Microsoft Word subscription.

Boost Your Workflow: Embrace the Magic of ChatGPT

Interacting with our friendly AI, ChatGPT, is very easy. All you need to do is type a message in Microsoft Word, select it, and click the "AskChatGPT" button in the shiny new "Advanced Functions" tab. Watch in awe as the AI's response magically appears right under your message!

Want to switch topics? Simply type a fresh message, hit "AskChatGPT" again, and voila! You're now brainstorming with an AI! Need an outline for a PRD (Product Requirements Document)? Just ask, "Hey ChatGPT, can you give me an outline for a PRD?" Then sit back and marvel at how ChatGPT creates a detailed, well-structured outline in a jiffy. Following are the step by step instructions on how to Integrate MS-Word and ChatGPT, with an example of a response in the end.


Setting up ChatGPT in Microsoft Word

Step 1- Enable the Developer Tab

By default, the Developer tab is hidden in Word. To enable it, go to 'File' > 'Options' > 'Customize Ribbon' and check the 'Developer' box. More instructions are available here.

No alt text provided for this image
Enable Developer Tab from "Customize Ribbon" Section under File ->Options

Step 2 - Write the VBA script

  • Open Microsoft Word and create a new or existing document.
  • Press Alt+F11 to open the Visual Basic for Applications (VBA) editor.
  • In the VBA editor, insert a new module by clicking on "Insert" and selecting "Module".
  • Copy and paste the following code into the module:

Sub AskChatGPT()


? ? ' Check if any text is selected in Word
? ? If Selection.Type = wdSelectionIP Then
? ? ? ? Exit Sub
? ? End If
? ??
? ? If Selection.Text = ChrW$(13) Then
? ? ? ? Exit Sub
? ? End If
? ??
? ? ' Set the API key and model details
? ? Dim apiKey As String
? ? apiKey = "YOUR_API_KEY"
? ??
? ? Dim endpoint As String
? ? endpoint = "https://api.openai.com/v1/completions"
? ??
? ? Dim modelName As String
? ? modelName = "text-davinci-003"
? ??
? ? Dim maxTokens As Integer
? ? maxTokens = 2048
? ??
? ? ' Get the user prompt from the selected text
? ? Dim userPrompt As String
? ? userPrompt = Replace(Selection.Text, ChrW$(13), "")
? ??
? ? ' Replace "\n" with vbCrLf for line breaks
? ? userPrompt = Replace(userPrompt, "\n", vbCrLf)
? ??
? ? ' Create the request JSON data
? ? Dim requestData As String
? ? requestData = "{""model"": """ & modelName & """, ""prompt"": """ & userPrompt & """, ""max_tokens"": " & maxTokens & "}"
? ??
? ? ' Create an HTTP request object
? ? Dim httpRequest As Object
? ? Set httpRequest = CreateObject("MSXML2.XMLHTTP")
? ??
? ? ' Send the API request
? ? With httpRequest
? ? ? ? .Open "POST", endpoint, False
? ? ? ? .SetRequestHeader "Content-type", "application/json"
? ? ? ? .SetRequestHeader "Authorization", "Bearer " & apiKey
? ? ? ? .Send requestData
? ? ? ??
? ? ? ? ' Check the response status
? ? ? ? Dim statusCode As Integer
? ? ? ? statusCode = .Status
? ? ? ? If statusCode <> 200 Then
? ? ? ? ? ? MsgBox "An error occurred while processing your request. Please try again later."
? ? ? ? ? ? Exit Sub
? ? ? ? End If
? ? ? ??
? ? ? ? ' Retrieve the response text
? ? ? ? Dim responseText As String
? ? ? ? responseText = .responseText
? ? ? ??
? ? ? ? ' Extract the completion text from the response
? ? ? ? Dim completionText As String
? ? ? ? Dim startIdx As Integer
? ? ? ? Dim endIdx As Integer
? ? ? ? startIdx = InStr(1, responseText, Chr(34) & "text" & Chr(34)) + 12
? ? ? ? endIdx = InStr(1, responseText, Chr(34) & "index" & Chr(34)) - 2
? ? ? ? completionText = Mid(responseText, startIdx, endIdx - startIdx)
? ? ? ??
? ? ? ? ' Replace "\n" with vbCrLf for line breaks in the completion text
? ? ? ? completionText = Replace(completionText, "\n", vbCrLf)
? ? ? ??
? ? ? ? ' Format and insert the completed text into the document
? ? ? ? With Selection
? ? ? ? ? ? .Collapse Direction:=wdCollapseEnd
? ? ? ? ? ? .InsertAfter vbCrLf & completionText & vbCrLf
? ? ? ? ? ? .Font.Name = "Arial"
? ? ? ? ? ? .Font.Size = 12
? ? ? ? ? ? .ParagraphFormat.Alignment = wdAlignParagraphJustify
? ? ? ? ? ? .ParagraphFormat.SpaceAfter = 6
? ? ? ? ? ? .Collapse Direction:=wdCollapseEnd
? ? ? ? End With
? ? End With
? ??
? ? ' Clean up objects
? ? Set httpRequest = Nothing


End Sub        

  • Replace "YOUR_API_KEY" in the code with your actual OpenAI API Key. Your openAI API key should look soemthing like "sk-1XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXVhG"
  • Save the VBA module by clicking on "File" and selecting "Save".
  • Close the VBA editor.


Step 3 - Create "AskChatGPT" button

Go to 'File' > 'Options' > 'Customize Ribbon', then click 'New Tab'. Rename the tab to 'AskChatGPT' and the group to 'Advanced Functions'. Under 'Choose Commands from', select 'Macros'. Add the 'AskChatGPT' Macro, rename the button to 'AskChatGPT', choose a symbol, and click 'OK'.

No alt text provided for this image
Under Customize Ribbon option, Add a new Tab and a new button "AskChatGPT"


No alt text provided for this image
Connect "AskChatGPT" button to your macro "AskChatGPT"


No alt text provided for this image
You can chose a different icon for your newly created "AskChatGPT" button


Boosting Productivity

Starting a chat with ChatGPT is straightforward. Type a message in Microsoft Word, select it, and click the 'AskChatGPT' button in the "Advanced Functions" tab. The model's response will appear beneath your message. Continue the chat by repeating these steps.

For instance, Let's ask ask the chatbot to help with an outline for a Product Specification. Input "Compose a concise product specification document for a healthcare tech website, outlining key features, user interface, and data security measures. Emphasize seamless patient experience and integration with existing healthcare systems," and the chatbot could respond with a well-structured outline for your document, saving you considerable time.


No alt text provided for this image
Select the text to ask ChatGPT and press "AskChatGPT" button
No alt text provided for this image
ChatGPT produced structuted Product Specifications Document response with neatly organised headings


The Future is Now: Embrace the AI Revolution

The seamless integration of ChatGPT into Microsoft Word isn't just about having a cool, new feature. It's a giant leap into the future of writing and content creation. Whether you're a professional writer, a student, a business analyst, or just someone who frequently uses Microsoft Word, ChatGPT is your personal AI buddy, ready to help you navigate the world of documents with efficiency and ease.

So, are you ready to step into the future? Embrace the AI revolution with ChatGPT and watch your productivity soar! Remember, the future belongs to those who dare to imagine, innovate, and implement. Welcome aboard this exciting journey with ChatGPT, your friendly AI companion in the digital world.

要查看或添加评论,请登录

Santhosh Kumar Setty的更多文章

社区洞察

其他会员也浏览了