XL: How to Run a WordBasic Macro from an MS Excel Macro

Last reviewed: September 2, 1997
Article ID: Q128405
The information in this article applies to:
  • Microsoft Excel 97 for Windows
  • Microsoft Excel for Windows 95, versions 7.0, 7.0a
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows, versions 5.0, 5.0c
  • Microsoft Word 97 for Windows
  • Microsoft Word for Windows 95, version 7.0
  • Microsoft Word for Windows NT, version 6.0
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c

SUMMARY

In Microsoft Excel for Windows, you can create a Microsoft Excel macro that uses either dynamic data exchange (DDE) or OLE Automation with Microsoft Word to run a WordBasic Macro. The purpose of this article is to demonstrate, by example, how to run a WordBasic macro using both of these methods.

MORE INFORMATION

Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Example 1

' The following macro demonstrates how to run the WordBasic macro
' "Macro1" by using DDE

Sub RunWordMacro_DDE()
Dim chan

   ' Initiate a channel with Microsoft Word.
   chan = DDEInitiate("Winword", "System")

   ' Execute a command on the channel to run the Wordbasic macro.
   DDEExecute chan, "[Toolsmacro.name=""Macro1"",.Run]"

   ' Terminate the channel.
   DDETerminate chan

End Sub

Example 2

' The following macro demonstrates how to run the WordBasic macro
' "Macro1" by using OLE Automation

Sub RunWordMacro_OLE()
Dim WordObj As Object

   ' Create the WordBasic object.
   Set WordObj = CreateObject("Word.Basic")
   '
   ' In Microsoft Excel 97, the line of code to use is
   '
   ' Set WordObj = CreateObject("Word.Basic.8")

   ' Run the WordBasic macro "Macro1".
   With WordObj
       .ToolsMacro Name:="Macro1", Run:=True
   End With

   ' Set the WordBasic object to nothing to end OLE Automation.
   Set WordObj = Nothing

End Sub


For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120979
   TITLE     : How to Use Named WordBasic Arguments in OLE Automation


Additional query words: 5.00 7.00 97 WORD7 WORD97
Keywords : IntpDde kbhowto kbinterop kbmacro kbole kbprg
Version : 5.00 5.00c 7.00 7.00a 97
Platform : WINDOWS


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 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.