OFF97: CALL Statement Cannot Accept Variable ArgumentLast reviewed: July 15, 1997Article ID: Q171134 |
The information in this article applies to:
SYMPTOMSIn Word, you can use the Visual Basic for Applications CALL statement to run another subroutine; however, you cannot specify the name of the subroutine by using a string variable or concatenated strings. Attempting to do so may result in the following error:
Compile Error: Syntax error WORKAROUNDMicrosoft 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. In cases where the name of the macro originates from a string variable (such as when you type information in a dialog box), you can use the following macro code: If A$ contains the name of the macro, use this statement:
Application.Run A$Or, if you are using literal strings:
Application.Run "Normal.Module1.MAIN" Application.Run "MyProject.MyModule.MyProcedure" Application.Run "'My Document.doc'!ThisModule.ThisProcedure"If you specify the document name, your code can run macros only in documents related to the current context: it cannot run any macro in any document. Although Visual Basic code can call a macro directly (without using this method), this method is useful when the macro name is stored in a variable. The following two statements are functionally equivalent:
Normal.Module2.Macro1 Application.Run MacroName:="Normal.Module2.Macro1"In cases where you call a literal string such as "AutoExec.Main," you must remove the quotation marks, as shown in the following example:
CALL AutoExec.MainNOTE: You cannot pass parameters to a macro by using the Run method.
MORE INFORMATIONThe CALL statement uses the following syntax to call another subroutine
CALL <subroutinename>where <subroutinename> is the name of the subroutine. In Visual Basic for Applications, you can use the following command
Call [<Template>].[<Module>].<Macro_or_ProcedureName>where <Template> is the name of the template, <Module> is the name of the module, and <Macro_or_ProcedureName> is the name of the macro or procedure. In all cases, the argument for the CALL statement must be explicitly defined. For example, both
CALL A$ -and- CALL "AutoExec.main"cause the error:
Compile Error: Syntax error REFERENCESFor more information about the Call statement, please see the following articles in the Microsoft Knowledge Base:
ARTICLE ID: Q164058 TITLE : Passing Procedure Arguments in Visual Basic for Applications ARTICLE ID: Q165518 TITLE : Calling Macros Using OLE from MS Visual Basic for Applications ARTICLE ID: Q114696 TITLE : Error Using Call Statement with Function ProcedureFor more information about the Call Statement, switch to the Visual Basic Editor, click the Office Assistant, type "Call," click Search, and then click to view "Call Statement."
|
Additional query words: offcon vb vba vbe
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |