Passing arguments to Word macros (2)

This post is an enhancement of the solution presented here Passing Arguments to Word macros

The current solution also provides a modified runmacro.vbs script but this time the script is enhanced such that it will accept 0 to 10 arguments for the Word macro. Also you can run the macro directly from RPE without having to use the post-processing command. Still that has its uses as you will see below.

The modified macro and examples are available here [RPE DevWorks Template Community]

Deploying the solution

  1. make a backup of runmacro.vbs from %RPE_HOME%\utils\word
  2. copy the runmacro.vbs from the archive in %RPE_HOME%\utils\word

Running the macro from RPE

  1. specify the file containing the macro in the stylesheet property of the Word output
  2. in the macro field of the RPE Word output specify the name of the macro followed by the arguments

In the example above the value entered in the macro field is: test “Hello – ” “Dragos”

  • test – the name of the macro
  • “Hello – “ – the first macro argument
  • “Dragos” – the second argument

The macro from the example will display a popup dialog showing the concatenation of the two values.

NOTE the arguments MUST be enclosed in quotes if they contain white spaces. If the value does not contain white spaces you can omit the quotes but using them is equally right.

Running the macro from RPE through the post-command feature

This allows for a more dynamic macro that can use the value of template variables.

  1. specify the file containing the macro in the stylesheet property of the Word output
  2. in the post-command field of the document specification enter the following
cscript "D:\Program Files (x86)\IBM\Rational\Publishing Engine\1.1.2\utils\word\runmacro.vbs" "${Word}" test "Hello - " "${varA}"

How it looks in RPE:

NOTE: replace D:\Program Files (x86)\IBM\Rational\Publishing Engine\1.1.2 with the RPE installation folder in your environment.

The parts of the command explained:
cscript – the command to start the Windows Script interepreter that will run the runmacro.vbs

  • “D:\Program Files (x86)\IBM\Rational\Publishing Engine\1.1.2\utils\word\runmacro.vbs” – the path to the runmacro.vbs. Enclosed in quotes as it contains whitespaces
  • “${Word}” – the first argument for the script is always the Word document that contains the macro to run. The ${Word} variable is replace by RPE with the actual path of the RPE Word output. For more details see Output processing through user defined commands
  • test – the name of the macro
  • “hello – “ – the first macro argument
  • “${varA}” – the second macro argument. This is replaced by RPE with the value of the varA template variable at the end of the execution. It is enclosed in quotes as it might contain whitespaces

If you look at the log generated by RPE when using the macro approach explained earlier in this post you will notice this very same command being executed. The major differences between using the macro vs the post command solution are:
– the macro solution requires only the macro name and its arguments.
– the post command solution supports dynamic content ( the value of RPE template variables)

The result is below. The template assigns to varA the name of the OS user ( in my case Spurlos)

Author: Dragos Cojocari

Architect for Rational Publishing Engine

9 thoughts on “Passing arguments to Word macros (2)”

  1. Thanks a tonne for the post, will definitely try this out. Use of cscript is also very interesting and it does open up a lot of possibilities indeed…. My next question is, and I know perhaps I need to look into cscript, can we dynamically rename the output file to include baseline information etc. from DOORS?

    1. Hey Vijay,

      you can use RPE’s post processing commands to rename any of the output files. And since in the post-processing command you have access to all the variables in the template you can have such a variable hold the module name. The only shortcomming of this approach is that RPE will still show the original/default name for the output in the results dialog.


  2. Ok… I tried downloading the files but the testMacro.doc does not contain any macros…
    I presume that I can create a test macro that uses msgbox statement, now sure how to refer to the arguments though!

      1. I still don’t see the macro. 😦 I see a date of 7/13 on the file but no macro. There are actually no macros at all in there.

      2. Hey Letty,

        you won’t see this listed as a macro since it has arguments. To see it you need to open the “Visual Basic” from the “Developer” tab and you will see the following if you select the “TestMacro” entry.

        Public Sub test(var1 As String, var2 As String)
        MsgBox var1 & ” – ” & var2
        End Sub


  3. Hello Dragos,

    thank you for your post. I’m really interested in this topic, but I can’t find the files for this example. As I understand it correctly I need the updated “runmacro.vbs” otherwise I can’t pass the arguments. Could you please tell me how to update the runmacro.vbs file?

    Thanks a lot

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s