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

Last reviewed: September 13, 1996
Article ID: Q94364

The information in this article applies to:

  • Microsoft Excel for Windows, versions 3.x, 4.x, 5.0, 5.0c
  • Microsoft Excel for Windows 95, 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("winword","system")
   A2:   =EXECUTE(A1,"[ToolsMacro.Name=""TEST"",.Run]")
   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

    "TEST".

    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.

REFERENCES

"Function Reference," version 4.0, pages 139-140 "Function Reference," version 3.0, pages 71-72


KBCategory: kbinterop
KBSubcategory:

Additional reference words: 7.00 3.0 3.00 4.0 4.00 4.0a 4.00a 5.0 5.00
word basic run



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 13, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.