Running Word for Windows Macro from Visual Basic Program

Last reviewed: July 30, 1997
Article ID: Q74653
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0

SUMMARY

It is possible to write a Visual Basic program to communicate with Microsoft Word for Windows using DDE (Dynamic Data Exchange). The following example displays the syntax necessary to run a Word for Windows macro from a Visual Basic application:

   Const COLD = 2
   Const NONE = 0
   Const HOT  = 1


   Sub Compic2_Click ()
   compic2.LinkTopic = "WinWord|system"
   compic2.LinkMode = COLD
   a% = DoEvents()
   compic2.LinkExecute [Hellomacro]
   compic2.LinkMode = NONE
   End Sub

MORE INFORMATION

The most important part of this macro from the Word for Windows viewpoint is the syntax to communicate with Word for Windows specifically. The command that actually executes the macro is the .LinkExecute command. This is the Visual Basic equivalent of the DDEExecute in Word for Windows. The correct lines of code to run a Word for Windows macro should follow this syntax:

   compic2.LinkTopic = "WinWord|system"
   compic2.LinkMode= either HOT OR COLD
   compic2.LinkExecute [Macroname]
   (you should always close the link as the example does)

REFERENCES

"Microsoft Visual Basic Programmer's Guide," pages 354-376

Kbcategory: kbusage kbmacro KBSubcategory:


Additional query words: winword2 6.0 6.0a 6.0c 1.x 2.0 winword
word7 word6 6.0a 6.0c 7.0 word95 2.0a 2.0a-CD 2.0b 2.0c
Version : 1.x 2.x 6.0 6.0a 6.0c 7.0
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: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.