Article ID: 128405 - Last Review: January 19, 2007 - Revision: 2.4

How to Run a WordBasic Macro from an MS Excel Macro

This article was previously published under Q128405

On This Page

Expand all | Collapse all

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 programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

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:
120979  (http://support.microsoft.com/kb/120979/EN-US/ ) How to Use Named WordBasic Arguments in OLE Automation

APPLIES TO
  • Microsoft Excel 97 Standard Edition
  • Microsoft Excel 95 Standard Edition
  • Microsoft Excel 5.0 Standard Edition
  • Microsoft Word 97 Standard Edition
  • Microsoft Word 95 Standard Edition
  • Microsoft Word 6.0c
  • Microsoft Word 6.0 Standard Edition
Keywords: 
KB128405
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
 

Article Translations