How to Run a VBA Macro in Word

The RT Client does not have a library function to directly execute a VBA macro in a Word document. RT Designer does allow you to run or inject & run a macro in MS Excel. So, the VBA code that is intended to run from a Word document can be executed via a macro in Excel.

For example, the following is the sample VBA code stored in a Word document that displays a message box.

To run the macro via RT Designer, create a dummy Excel file and use the VBA code below to call the Word function via Excel.

To run the function in RT Designer, use Library Objects > MS Office Functions > Inject And Run Excel Macro.

Note: There is also a DLL available from NICE Services that allows you to run VB scripts directly in Word documents.

Download Project Files

  1. Download the project file here.

  2. Unzip the files.

  3. Copy the Excel and Word files to C:\TEST.

Explore the Sample

  1. Open the project file in RT Designer.

  2. Select Business Logic > Event Handlers to view the event with the code attached.

Test the Project

  1. Run the project.

  2. The event is triggered and the macro runs in Excel and calls the macro in Word.