OFF97: CALL Statement Cannot Accept Variable Argument

Last reviewed: July 15, 1997
Article ID: Q171134
The information in this article applies to:
  • Microsoft Visual Basic for Applications included with:

        - Microsoft Word 97 for Windows
        - Microsoft PowerPoint 97 for Windows
        - Microsoft Excel 97 for Windows
    

SYMPTOMS

In 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

WORKAROUND

Microsoft 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.Main

NOTE: You cannot pass parameters to a macro by using the Run method.

MORE INFORMATION

The 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

REFERENCES

For 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 Procedure

For 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
Keywords : kbprg
Version : 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbinfo


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 15, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.