A node.js service for running Word Macros remotely

Word macros allow document creators to correct document  errors and fine tune the document formatting. Running the macros programatically through Word automation allows to automate the process for added benefits. There are a number of tools and processes that do this with  RPE being one of them.

Running macros is limited to the Windows platform  and it’s subject to additional limitations such as Word automation not being supported from NT Services ( as it’s the case for running RPE/RRDG running in WAS or Tomcat in Service mode).

To enable macros to run in situations where Word or Word automation is not available the solution is to execute the macros remotely by a dedicated service. Microsoft offers such a service in the form of Word Automation Services. Another solution, the one described in this article, is to a service that runs the macros through Word automation. The caveat of this service is that it cannot run as an NT service, it must run in an interactive desktop ( Apache Tomcat in console mode or node.js).

DISCLAIMER: The solution described in this article is provided as-is without warranty of any kind, express or implied. The service is not part of RPE and it is not supported by IBM.

Run Macro Service

runmacro is such a node.js service that exposes a very simple REST API for running macros. The service comes with an HTML example to help visualize how the service works.


The service code is freely available on Github at https://github.com/dragoscojocari/nodejs-runmacro. You can get its source code via the “Download ZIP” option.  See the project’s Readme for details on installation and usage.

DISCLAIMER: the service and the associated example is provided as-is without warranty of any kind, express or implied. This is not part of RPE and it is not officially supported by RPE.

Using the service

To use the service you can either go for the HTML based approach ( which is entirely manual) or use a tool like curl so you can automate the process. Below is the example of the curl command that does this:

curl --form "document=@d:\tmp\testMacro.doc;filename=testMacro.doc" --form macro=insertDate -o d:\tmp\documentAfterMacro.doc

Using the service in RPE

The easiest way to integrate this in RPE is by modifying the runMacro.vbs script from %RPE_HOME%\utils\word.  In my environment I have the following:

  • a folder for curl. exe and its dependencies in a d:\tools\curl
  • a Windows bat file, runRemoteMacro.bat for running the curl. This allows changing the curl command more easily compared to embedding the command directly in the VBS file.
  • modified the runMacro.vbs that ships with RPE to invoke the bat file instead of calling Word through automation.

The bat and vbs files are included in the Git repository in the “Client” package.

Once you’ve done these changes the macros will be executed on the remote server instead  of the local machine with no changes in the end user experience. However this is limited to Windows machines as you need Windows’ cscript to run the vbs file. For Linux machines the solution is to use post-processing commands.


Author: Dragos Cojocari

Architect for Rational Publishing Engine

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s