The information in this article applies to:
SUMMARYThis article describes how to create a routine in Microsoft Visual Basic for Applications that uses named and position arguments to send commands to Word for Windows using OLE Automation. For example, you can send OLE Automation commands to Word from a Microsoft Excel Visual Basic for Applications macro to perform a print merge operation in Word (see the "Sample Visual Basic for Applications Module to Run Mail Merge in Word" section at the end of this article). MORE INFORMATIONThe syntax for named arguments in Visual Basic, Applications Edition, is similar to the WordBasic syntax in Word for Windows. You can see the similarities in the following sample WordBasic and Visual Basic for Applications syntax, both of which start a new Word document based on the LETTER1.DOT template: WordBasic Syntax
Visual Basic, Applications Edition, Syntax
NOTE: The syntax differences are small but significant. In Visual Basic for
Applications, the Word command is preceded by a period (.), there is no
period (.) before the command arguments, and a colon (:) appears before the
equal sign (=). If your Visual Basic for Applications syntax is incorrect,
the following error message may occur:
Sample Visual Basic for Applications Module and WordBasic MacroWARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.The following sample Visual Basic for Applications module uses OLE Automation to send named arguments to Word and create a new document:
NOTE: Word should be active before you run this Visual Basic for
Applications module. If Word is not running, you will not see the result in
Word because when OLE Automation starts Word, OLE closes Word after the
Visual Basic for Applications module runs.
The following is the WordBasic macro equivalent of the above Visual Basic for Applications module:
Sample Visual Basic for Applications Module to Run Mail Merge in WordFor the following mail merge example to work, you need to have Word 6.x running with a main mail merge document open.
REFERENCES"Microsoft Word Developer's Kit," version 6.0, Microsoft Press, 1994, pages 174-182 Additional query words: winword 6.0 7.0 word95 word7 word6
Keywords : kbinterop kbmacro kbole kbmerge |
Last Reviewed: December 20, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |