Microsoft KB Archive/94364

{|
 * width="100%"|

Excel: How to Run a Word for Windows Macro from Excel

 * }

-

The information in this article applies to:


 * Microsoft Excel for Windows, versions 3.x, 4.x, 5.0, 5.0c
 * Microsoft Excel for Windows, version 7.0

-

SUMMARY
In Microsoft Excel for Windows, you can use the EXECUTE function to run version 2.0 Microsoft Word for Windows macros in a dynamic data exchange (DDE) macro.

MORE INFORMATION
Microsoft provides macro examples for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This macro is provided 'as is' and Microsoft does not guarantee that the following code can be used in all situations. Microsoft does not support modifications of the code to suit customer requirements.

The following is a sample macro that runs a Microsoft Word for Windows macro called TEST from Microsoft Excel. In order to run this macro, use the WordBasic command ToolsMacro in the EXECUTE function.

  A1:   =INITIATE(&quot;winword&quot;,&quot;system&quot;) A2:  =EXECUTE(A1,&quot;[ToolsMacro.Name=&quot;&quot;TEST&quot;&quot;,.Run]&quot;) A3:  =TERMINATE(A1) A4:  =RETURN

For more information about the ToolsMacro function choose Help Index from the Help menu in Word for Windows, search on WordBasic, select WordBasic Programming Language, choose the Go To button, and select ToolsMacro from the list of WordBasic functions and statements.

Explanation of Macro
A1: Initiates the channel to Word for Windows.

A2: Executes the ToolsMacro WordBasic command to run the macro called &quot;TEST&quot;.

NOTE: The two quotation marks on each side of the macro name are required to produce the one set of quotation marks needed by Word.

A3: Terminates the DDE channel to Word for Windows.

A4: Ends the macro.