ChatGPT for Microsoft Word: A Step-by-Step Guide

In this post we will cover how to integrate ChatGPT into Microsoft Word. ChatGPT can boost your productivity, and significantly improve your writing capabilities. Those who don't know ChatGPT, it is a state of the art language model which provides human like responses. It has gained huge popularity in recent months.

Run ChatGPT in MS Word
Table of Contents

Benefits of using ChatGPT in MS Word

ChatGPT can be used to improve your writing and generate content for you in Microsoft Word. See some of the ways you can use it in Word -

  • Generate a tailored resume for the job based on the job description
  • Generate content for blog posts or articles
  • Summarise lengthy reports for you
  • Provide suggestions for social media posts
  • Create templates for emails and proposals
  • Help non-native speakers in translating in other languages

How to Use ChatGPT in Microsoft Word

Integrating ChatGPT into MS Word has never been easier with the ChatGPT add-in. You can download the add-in using the link below. It is absolutely free and and can run on all the versions of Office Desktop and Office 365. Also there are no prerequisites for using this add-in.


Get OpenAI API Key

First you need to sign up by visiting OpenAI website using this link - platform.openai.com. By using your existing Google or Microsoft account you can do it easily. Last step is to get secret API key to use OpenAI API. Copy your API key for future reference. API Key looks like the text below

sk-xxxxxxxxx

Steps to install add-in

Microsoft blocks external add-in files and says the source of this file is untrusted. To make the file trusted, you need to follow the steps below.

  1. Go to the folder where the downloaded add-in file is located.
  2. Right-click the file and choose Properties from the menu.
  3. At the bottom of the General Tab, select the Unblock checkbox under security option and then click Ok

To make the add-in to be available each time you launch MS Word, you can save it in the Startup folder. Follow the steps below.

  • Go to File > Options > Advanced.
  • Scroll down to General and click on File Locations.
  • Click on Startup > Modify and then you have two options - Either you locate the folder where downloaded add-in file is stored. OR Instead of changing the Startup folder location, you can also paste the add-in in the existing Startup folder.
    It is recommended to use the latter option. If you prefer first option, make sure to create a new folder and put the downloaded add-in file there and then navigate the location of Startup folder to this new folder. It is because if you use a folder for e.g. Download/Documents folder which may contain so many word files, it is likely MS Word would crash.

How to use ChatGPT add-in

Follow the steps below to use ChatGPT add-in for MS Word.

  1. Open a new or existing MS Word document
  2. Type the text you want to ask ChatGPT
  3. Select the text you typed in the previous step
  4. Click on ChatGPT Tab > AI Writer
  5. Enter your API Key
  6. Output will be generated and appeared in a few seconds
  7. Output will be saved in a new word document in the same folder where your active word document is stored
  8. File name of output file is output_mm-dd-yyyy_hr-min-sec.docx
Resume Builder

You can generate resume with this add-in. It is important that you provide a clear and detailed prompt so that ChatGPT generates resume according to your requirements. Always be specific and try with multiple prompts for best outcome. See some of the examples below -

Write a professional resume for a [Profile Name]. I have [N] years of experience. My past titles and companies were [Title, Company Name]. Include bullet points.
Write a professional resume for a Data Scientist. I have 5 years of experience. My past titles and companies were Analyst, Barclays, Team Lead, JP Morgan. Include bullet points.
Write a resume for a [Profile Name] based on this job description. [Add Job Description Here]
Email Writing

You can ask ChatGPT Add-in to draft email for you. Whether you need to send a formal business email or a friendly message to a colleague or friend, ChatGPT can help you write a professional and well-drafted message. You just need to provide the purpose of email and some context and ChatGPT will generate a well-written email for you. You can also choose the tone of email.

Write an email to manager about sick leave tomorrow. My Manager’s name is Dave. My name is Deep.
Write an email to colleague about personal leave tomorrow. My colleague’s name is Joe. My name is Deep. Tone should be informal.

It's also good to specify tone - formal / informal/ humorous.

Summary Writing

ChatGPT Add-in can be used to summarize lengthy word document for you. For example you have a long document and you are asked to create summary based on it. It may be time consuming and boring to read the whole text and then write summary.

Summarise the text below in bullet points - [PASTE TEXT HERE]

How to style ChatGPT Output?

You can style MS Word Document by adding the following lines to the end of the prompt you ask ChatGPT

  • Highlight the headings in dark blue color.
    Write a resume for a Software Engineer. Highlight the headings in dark blue color.
  • Include bullet points.
  • Please format the text to be italic.
  • Text should be in red colour.

In the next section we will see the source code of this add-in. If you are not interested in knowing the source code, you can skip the next section. The add-in and VBA code serve the same purpose.

The benefit of using add-in is that it opens automatically every time you open a new word document. Whereas MS Word Macro file is specific to a particular word document. You have to open the same macro file each time to access ChatGPT. Also the add-in performs formatting in the word document.

VBA Code to run ChatGPT in MS Word

You can use the VBA Code below to run ChatGPT inside MS Word. Make sure to change API Key (highlighted in yellow below)

Sub chatGPT()

    Dim request As Object
    Dim text As String, response As String, API As String, api_key As String, DisplayText As String, error_result As String
    Dim startPos As Long, status_code As Long
    Dim prompt As String
    Dim selectedText As range

    'API Info
    API = "https://api.openai.com/v1/chat/completions"
    
    'API Key
 api_key = "sk-xxxxxxxxxxxx"

    If api_key = "" Then
        MsgBox "Error: API key is blank!"
        Exit Sub
    End If
    
    ' Prompt the user to select text in the document
    If Selection.Type <> wdSelectionIP Then
        prompt = Trim(Selection.text)
        Set selectedText = Selection.range
    Else
        MsgBox "Please select some text before running this macro."
        Exit Sub
    End If
        
    'Cleaning
    text = Replace(prompt, Chr(34), Chr(39))
    text = Replace(text, vbLf, "")
    text = Replace(text, vbCr, "")
    text = Replace(text, vbCrLf, "")

    ' Remove selection
    Selection.Collapse

    'Create an HTTP request object
    Set request = CreateObject("MSXML2.XMLHTTP")
    With request
        .Open "POST", API, False
        .setRequestHeader "Content-Type", "application/json"
        .setRequestHeader "Authorization", "Bearer " & api_key
        .send "{""model"": ""gpt-3.5-turbo"",  ""messages"": [{""content"":""" & text & """,""role"":""user""}]," _
             & """temperature"": 1, ""top_p"": 0.7}"
      status_code = .Status
      response = .responseText
    End With

    'Extract content
    If status_code = 200 Then
      Result = Split(response, """,""")
      For i = LBound(Result) To UBound(Result)
        If InStr(Result(i), "content") > 0 Then
                startPos = i
                Exit For
        End If
     Next i
      DisplayText = Mid(Result(startPos), InStr(Result(startPos), ":") + 2, InStr(Result(startPos), """},"))
      DisplayText = Mid(DisplayText, 1, InStr(DisplayText, """},") - 1)
      DisplayText = Replace(DisplayText, "\""", Chr(34))
      DisplayText = Replace(DisplayText, "\n", vbLf)
                
    'Insert response text into Word document
    selectedText.InsertAfter vbNewLine & DisplayText

        
    Else
        startPos = InStr(response, """message"": """) + Len("""message"": """)
        endPos = InStr(startPos, response, """")
        If startPos > Len("""message"": """) And endPos > startPos Then
            DisplayText = Mid(response, startPos, endPos - startPos)
        Else
            DisplayText = ""
        End If
        
        'Insert error message into Word document
        EDisplayText = "Error : " & DisplayText
        selectedText.InsertAfter vbNewLine & EDisplayText
        
    End If
    
    
    'Clean up the object
    Set request = Nothing

End Sub
How to use VBA code

The following steps provide basic instructions for using VBA code in MS Word.

  1. Press Alt+F11 to open the VBA editor.
  2. Click Insert > Module to create a new module.
  3. In the module, paste the VBA code.
  4. Replace API Key in api_key with your actual API key.
  5. Close the VBA editor.
  6. Run the macro by pressing Alt+F8 and then select ChatGPT and hit RUN button.
If you want to use ChatGPT-4, you can replace gpt-3.5-turbo with gpt-4 in the above VBA code.

How to fine tune ChatGPT Output

In the above add-in/VBA code, you will come across a temperature parameter. It ranges from 0 to 2. Increasing the value, such as 1.2, will result in a more random output, whereas decreasing the value, like 0.2, will yield a more focused output.

Refer the detailed guide about how to run ChatGPT in MS Excel and PowerPoint
ChatGPT Plugin for MS Excel
ChatGPT Plugin for MS PowerPoint.
ListenData Logo
Spread the Word!
Share
Related Posts
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he has worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and Human Resource.

0 Response to "ChatGPT for Microsoft Word: A Step-by-Step Guide"

Post a Comment

Next → ← Prev
Looks like you are using an ad blocker!

To continue reading you need to turnoff adblocker and refresh the page. We rely on advertising to help fund our site. Please whitelist us if you enjoy our content.