top of page
Search

How to Use OpenAI APIs to Generate Action Items in Word: A Guide

  • Writer: Mark Stankevicius
    Mark Stankevicius
  • Apr 2, 2024
  • 12 min read

splash image conveying the concept of a Gen-AI powered action item generator in Word document

Introduction to automated action item generation

As we investigate Generative AI and its uses in everyday work tasks, there are more and more ways to incorporate Generative AI to help us become more productive.  In many ways, it aids us in our work by allowing us to complete tasks quicker and more accurately.  Generative AI can also help us comply with business templates and processes by guiding us and ensuring that what we create complies with standards that must be met for corporate, government, or standards bodies compliance.  By providing us with Generative AI-aided document creation using our business inputs, we can ensure that we comply with certain guidelines.

ChatGPT, an AI language model developed by OpenAI, is a quick and efficient method for generating automated action items from meeting minutes or discussions. With just a few clicks, you can create complete action items in Microsoft Word. This blog post will explain how to create a Gen-AI powered action item generator in a Word document.

In this step-by-step guide, I will take you through:

  1. Setting up Word for Developer enablement to code VBA (Visual Basic for Applications) macros

  2. Setting up the VBA code to call OpenAI APIs

  3. Setting up the API key to call the OpenAI API

  4. Running and testing the Macro call to the OpenAI API "chat/completions"

  5. Inserting the action items into a Word document and testing the Macro

  6. Adding a Word Ribbon action to invoke the Action Items macro


Introduction to the OpenAI (ChatGPT) API

The ChatGPT API empowers developers to incorporate the model’s capabilities into their applications, enabling programmatic text generation. Accessing the API is straightforward, allowing for creating prompts that ChatGPT can respond to with precision.  This can be done with other AI Chatbots and the APIs they expose, but for this tutorial, I will be using OpenAI APIs.

ChatGPT's capabilities are based on its ability to predict the next word or phrase given a prompt. By leveraging this capability, we can provide ChatGPT with meeting minutes and, using the correct prompt, let it generate a concise list of action items. With the current state of the art in Generative AI models, we will still need to review and modify the action items to suit our needs, but it very quickly gives us a starting point.

What is OpenAI-API? OpenAI provides several ways to use the power of generative AI. One approach is to programmatically call the OpenAI functions, which require an API. For this particular use case, the chat/completions API suits our needs to review and understand the meeting minutes and generate the action items.  By understanding how the OpenAI API works, we can seamlessly integrate the AI capabilities into our Word Macro to create a ChatGPT-generated list of action items.

 

Prereqs for these Step-by-Step instructions

There are several requirements for you to automate the calling of OpenAI APIs in a Word document. They are the following:

  1. An OpenAI API account: You will need access to the OpenAI APIs to call them directly from the Word Macros, which doesn’t require a ChatGPT Plus account but does necessitate an OpenAI API plan. You can find more details here: https://openai.com/product. The pricing model is quite affordable, based on the number of tokens utilized. Create an account before you begin the steps in this document.

  2. Familiarity with programming with Visual Basic (VB) macros in Microsoft Word: The OpenAI API will be called from a VB macro in the Word document. Therefore, some familiarity with programming would be helpful to ensure you can set up the environment and correctly copy the code for the ChatGPT Action Item generator.

  3. Access to Microsoft Word: I used “Microsoft® Word for Microsoft 365 MSO (Version 2402)” in these step-by-step instructions. Some steps may vary depending on your version, but the general approach will apply.

  4. Macro-enabled Word document: For security reasons, the default Word document type does not allow macros to be invoked. You must use a “Microsoft Word Macro-Enabled Document,” which allows you to create and add macros.

  5. Important Note: Enabling macros in Word documents could introduce malicious code. Some Malware is distributed via VB macros. In addition to the code I have written and provided, I use two other VBA macro libraries: VBA-JSON and VBA-Dictionary. I scanned both libraries with VB malware scanner to ensure they do not introduce malware into the word document.


Step-by-step guide to create a Gen-AI powered Action Item generator in Word

Now that we have a basic understanding of automated action item generation and the tools involved let's dive into the step-by-step tutorial on generating action items programmatically in Word.

In this automated action item generator, the input is what you would see as typical meeting minutes when discussing a project's status in a business meeting. The example I use is fictitious but represents what might be discussed when reviewing the status of an IT project.  I have chosen to use an approach in the Word document to indicate the location of the meeting minutes by using delimiters.  This was for convenience but could also be removed, and the VBA code could provide the entire Word document text as input.  The format that the macro will be looking for is a set of delimiters in the document that indicate where the minutes start and end.  The basic format is the following:

example of the Word document layout with the start and end delimiters

The VBA code will search and find the meeting minutes start and end markers of “meeting minutes start:” and “meeting minutes end”.  It will extract the text between these delimiters to use as input to the analysis for the action items. You can see these delimiters being defined in the VBA code where it sets the value for the variables “startString” and “endString”.  If you wish to use other delimiters, you can easily change the lines of code that assign the values to these variables.  

When you are ready to insert your meeting minutes, replace the text in red (shown above) with the text for the meeting minutes. This approach allows you to create a Word document template with these delimiters and type the meeting minutes between the start and end delimiters in the document. Then, once the meeting is done, run the Action Item Generator AI Macro to create the complete list of action items.

The VBA macro code instructs the OpenAI API on what action to take. I have documented the approach in the code using comments. The details must be specified in the OpenAI prompt to ensure the chat API performs the correct prompt action.



Step 1: Setting up Word for Developer enablement to code VBA macros

To interact with the OpenAI API, we must use a Word document with macro support. A Word Macro is a set of instructions that automates repetitive tasks in Word. In this case, we will use a Macro programmed in Visual Basic to invoke the OpenAI API, retrieve the generated action items, and insert them into the Word document.

To set up the Visual Basic Word macro, follow these steps:

1)   Open Word and navigate to the "Developer" tab.

2)   If you do not see the "Developer" tab in Word, add it to your view. It is not shown by default in the tabs in Word.

3)   To add the “Developer” tab, navigate to “File” -> “Options” -> “Customize Ribbon”

Image of Word Customize Ribbon dialog indicating "Developer" tab not selected

4)   Check the “Developer” Tab box and click “OK”

Image of Word Customize Ribbon dialog showing "Developer" tab checked

5)   Now you should see the “Developer” tab on your Ribbon

Image of Word Ribbon showing "Developer" tab

6)   The “developer” tab opens the Visual Basic Editor, which allows you to create Visual Basic macros to call OpenAI APIs. The steps to create and invoke the macro in the Word document are below.

With the Developer tab now in place, we're poised to integrate the OpenAI API in the subsequent phases of our setup.


Step 2: Setting up the VBA code to call the OpenAI API

1)   Open Word and navigate to the "Developer" tab.

2)   Click on "Visual Basic” to open the Microsoft Visual Basic for Applications (VBA) editor.

Image of Word toolbar showing the Visual Basic option
  • This will open the VBA editor in another window and allow you to create the macro needed to call the API.

3)   On the top toolbar of the VBA editor, select “Insert” -> “Module” to open an empty module creation window.  You will want to copy the below VBA code into this empty module window.  Copy and paste all the VB code into the new module.

4) Rename the module in the VBA editor window by choosing “View” -> “Properties Window”, which will open the properties for this new module.  Notice it is initially named “Module1”.  In the Properties window, choose a more meaningful name. I have chosen “ActionItemGen”  

Image showing the macro renamed to "ActionItemGen" in Word VBA editor

5)   The “JsonConverter” module is also used in this code and must be inserted and referenced for the macro code to run properly.  It is used to parse the response returned from the API.  If you do not import this module, you will receive a “Run-time error ‘424’ Object required”. Which indicates that the module cannot be found.  The instructions for installing this module can be found on the Readme page of that module's GitHub URL.  Import it using “File” -> “Import File” on the VBA editor toolbar.

6)    The JsonConverter library also depends on “VBA-dictionary”.  I also used the VBA Dictionary and imported it into the VBA editor. Download the zip file and extract it to a local folder. Then, import the “dictionary.cls” file into your VBA project using steps similar to those above. Once you have imported the JsonConverter and the Dictionary file, you will see the following in the VBA editor.

Image of Word VBA Editor showing the JsonConverter & Dictionary modules

        

There are a few things to note in the VBA macro:

  • The default model (LLMs - Large Language Models) used in the text generation is "gpt-4-turbo-preview" since it gave me the best results for the action items. You can change this to use other models of your choice. I suggest starting with gpt-3.5, and once you have everything set up and working, you can change it to other models that may give you better results in the action items generated.

  • The OpenAI API called to generate the text is the “chat/completions” API. This API is compatible with a specific list of language models, which changes over time. I recommend checking the OpenAI website to ensure you use a compatible model.

  • The crucial line of code that instructs OpenAI on the desired behavior is the line of code assigning a value to the “systemPrompt” variable. This directive is a key part of the ChatGPT action item prompt, and I’ve found it to be effective in guiding OpenAI in producing the most accurate set of action items.  You can modify these instructions to try different text and see the resulting set of action items.  You will notice that in the system prompt I also give guidance to OpenAI on the formatting of the action items to a format I desire for use in the Word document. 

  • The code has error handling to ensure the meeting minutes are found. If something is missing in the document and the text delimiters cannot be found, messages will be sent to the Word UI.


Step 3: Setting up the API key to call the OpenAI API

Keep going; your determination is about to be rewarded as you approach the final stages before you can create and execute the macro. Just a few more steps remain, and you'll be all set to give it a try.

1)   Copy your API key from the OpenAI API account site into the code.  The Macro will make an API call to the OpenAI endpoint, retrieve the generated content, and insert it into your Word document.  Login to your OpenAI API account that you created in the Prereqs step and access the API key tab in the menu or use this API Key link.

Image showing how to access the API keys tab in OpenAI UI

2)  In the API keys UI, click the “Create new secret key” button to create a new API key for the API call. 

Image showing the "Create new secret key" in OpenAI UI

        

3) Once the API key is created, copy it into the indicated line of macro code shown below. Carefully replace the placeholder with your unique key to ensure secure access to the OpenAI API from your personal account. Remember, this key is confidential and should not be shared, as it is your exclusive access to your account.

Image indicating where to enter the OpenAI API key in the macro

     

Step 4: Running and testing the Macro call to ChatGPT API

1) Now that you have the VBA macro created and using your API key, you can test the macro and ensure it is set up properly.  Ensure you have copied some example meeting minutes between the delimiters in the document. If the document is ready, go to the quick access toolbar and click Macros.

Image of Word quick access toolbar showing how to access the macros

      

2)  If you do not see the “View Macros” on the quick access toolbar, you will need to choose “File” -> “Options” -> “Quick Access Toolbar” and add “Macros”.

3)  Once you can view the macros, a window with the macros in your document will open, as indicated below. Select macro “ActionItemGen” and then click “Run” (you may have named your macro differently than shown), to run the macro on the currently open document.

Image of Word dialog showing how to Run a macro

4)  If the macro call to ChatGPT is successful, a list of action items will be generated and inserted into the Word document after any existing text.  I have included a screenshot of a partial example below:

Example output of the action items being generated and inserted in a Word document

  • If no text is inserted, check for any error messages indicating possible problems. If there are errors, check the steps above to ensure that all actions have been implemented properly.  You can also refer to the section Error resolution for a description of possible errors.

5)  The OpenAI chat/completions request body has a couple of parameters you can modify to try different outputs and determine which provides the best results. These are the "temperature", "top_p", “frequency_penalty”, and “presence_penalty” parameters. A detailed description of these parameters can be found in the OpenAI API documentation for Chat completions API.  To view the values I used, check the VBA code to see the setting that provided a good set of action items.

 

 

Step 5: Checking the action items generated for accuracy

While the AI Action item generator powered by ChatGPT provides a starting point, you will want to review the action items and ensure they are all accurate.  While testing this approach, I found that, at times, it missed some of the action items, did not estimate the due date properly, or got the details incorrect for the dependency.  There also may not be enough information provided in the minutes for ChatGPT to represent the action items correctly. Therefore, you may have to add missing information or correct due dates if you are aware of additional information that the minutes did not properly represent.

Although you'll probably need to revise the action items, this serves as a solid starting point and will require less time to update than creating them from the beginning.


Adding a Word Ribbon action to invoke the OpenAI API

To make accessing and invoking the Action Item generator more obvious and even easier, you can modify the Word document template to add a custom VBA macro button to the toolbar.  This will provide an easily visible way to invoke the Action Item AI generator, as shown below.

image showing ActionItemGen button on the Microsoft Word toolbar ribbon

To add this button, use the following steps:

1) In the Word document, choose "File" -> "Options" -> "Customize Ribbon" to open the tab to add custom items to the Word Ribbon.

image showing "Customize Ribbon" dialog in Word

2) Choose which tab you want to add the new macro to. The list of tabs is shown on the right side of the “Customize Ribbon” dialog.  In this example, I have chosen the "Home" tab and then clicked the “New Group” button. You must add a new custom group to be able to add the new item to the tab. I will use this new group to add the macro button.

Image showing in Word how to modify the Tabs to add a new custom group

3) Rename the new group to a more meaningful name using the "Rename" button. As shown, I rename it to "Action Items" and then click “OK” to apply the new name.

Image showing in Word how to rename the new custom group

4) Now, with the new "Action Items" group in place, you can add the macro to that group. On the customize ribbon tab under the "Choose commands from", select "Macros" in the drop-down, which will then display a list of the macros in the document.

Image showing in Word how choose macro dropdown to list document macros

5) Select the new action items macro called "ActionItemGen", then click "Add" to add the macro under the group "Action Items".  Be sure to select the new custom group “Action Items” to place the Macro button in the correct group.

Image showing in Word how Add the Macro to the "home" tab new group

6) You will notice by default it uses the full name for the display name of the macro. This may be too long for the ribbon. Therefore, you may want to rename the display name to something that is shorter, as shown below I rename it to "ActionItemGen" using the "Rename" button.

Image showing in Word the Macro "ActionItemGen" added to the custom group on the home tab

7) Don't forget to click "OK" to apply these changes to the existing Word document.


You will now see the macro button on the Word Toolbar Ribbon, making invoking the AI-generated Action Items macro easy. Simply click the button "ActionItemGen" on the Word Ribbon, and the AI code will review the meeting minutes and generate the list of action items.

 

Conclusion and future possibilities for automated action item generation

Automated action item generators are just one of many ways to aid you in your quest to simplify day-to-day tasks and improve your productivity. The above approach of integrating OpenAI Generative AI into a Word document is just one of many OpenAI use cases. Hopefully, this gives you a base to start with and will get you thinking about other tasks that can be similarly automated and reduce your workload.

As AI technology advances, the accuracy of the action items generated will continue to improve. With additional training on your business processes or templates, this process will become much more automated.

Automating action item creation with the OpenAI API in MS Word allows you to focus on the more difficult tasks that require further investigation and analysis and cannot be automated with Generative AI today. By following this step-by-step tutorial, you can harness the power of AI to improve your overall productivity and further contribute to the business's success.

 

Error resolution

There are a few possible problems you may encounter when running the generator. Below are some error conditions and possible resolutions:

  • Truncation of the text: If the action items generated look truncated, it’s likely due to the number of tokens specified in the request. The sample code limits it to 1000 tokens, and if your list of action items is extensive, you will need to increase this limit. To make this change, increase the number in the parameter “max_tokens” on the requestData.

  • If you encounter the error below, there is a problem with the JSON used as input to the chat/completions request.  A possible cause may be that the text extracted from the Word document has hidden ASCII characters. The function VBA “CleanText” removes some hidden ASCII characters, such as line feeds, but your text may have other characters causing issues in the JSON string.  To determine if this is the cause of the problem, you can display the hidden characters in the document with “File” à “Options” à “Display” and then check the “Show all formatting marks”.  This will display the formatting in the document.  If you have additional formatting characters that are not already handled by the “CleanText” function you will need to add code to remove the additional ASCII characters.

error message text if the JSON string in the OpenAI API call is incorrect
  • If you see the following error, it indicates that you have inserted the incorrect API key or that the API key is missing. Check that the API key is inserted into the proper location as indicated in Step 3.3 above and that it is the exact key from your OpenAI account. The variable “OpenAI_Api_Key” must contain your API key.

error text if the API key in the OpenAI call is incorrect

 

 
 
 

Comments


bottom of page