HOWTO: Passing Parameters to a Word 97 MacroLast reviewed: July 29, 1997Article ID: Q171988 |
The information in this article applies to:
SUMMARYWhen using OLE automation to Microsoft Word 97, it is often desirable to pass parameters from Visual FoxPro to the Word 97 object. The Run method is normally used to execute a Word macro through OLE automation; however, the Run method cannot accept parameters. To pass parameters to the Word object, there must be a public Word macro that is a method of a document or template.
MORE INFORMATIONIn Word 97, documents and templates have their own Visual Basic for Applications projects: a document project and a template project. Macros can be added as a Public Sub to either the document or template project. For illustration purposes, this article will create a public macro using Word default Normal.dot. If the public macro is added to a document, that document must be opened in order to call the macro. If the public macro MainMacro is added to a user template, named Testdot.dot stored in the Word directory on the C drive, for example, the following code can be substituted for the oWordDoc=oWordObj.Documents.Add in the Visual FoxPro code in the section below:
oWordDoc=oWordObj.documents.Add("C:\word\testdot.dot") Steps to create the Public Word macro
Visual FoxPro codeCreate a new program and enter the following code:
CLEAR PUBLIC cname,nnum cname=SPACE(15) nnum=0 @ 2,2 SAY "Enter a name to display" GET cname @ 4,2 SAY "Now enter a number " GET nnum READ oWordObj=CREATEOBJECT('word.application') oWordDoc=oWordObj.Documents.Add oWordDoc.MainMacro(cname,nnum) oWordObj.QUIT REFERENCESMicrosoft Word Visual Basic Help (c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Dean Christopher, Microsoft Corporation
Keywords : FxinteropWinword vfoxwin kbcode Technology : kbole Version : WINDOWS:3.0,3.0b,5.0,5.0a Platform : WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |