ExecuteLine method

Microsoft Visio Developer Reference

ExecuteLine method

   Example   

Executes a line of Microsoft Visual Basic code.

Version added

4.5

Syntax

object.ExecuteLine stringExpression

object

Required. An expression that returns a Document object.

stringExpression

Required String. A string that will be interpreted as Microsoft Visual Basic for Applications (VBA) code.

Remarks

The VBA project of the Document object is told to execute the supplied string. VBA treats the string as it would treat the same string typed into its Immediate window.

The ExecuteLine method creates a VBA project in the document if one does not exist.

Here are some possibilities:

ThisDocument.ExecuteLine("SomeMacro")
    'Executes the macro (argumentless procedure) named SomeMacro
    'that is in some module of the VBA project of ThisDocument. 
    
ThisDocument.ExecuteLine("SomeProc 1, 2, 3")
    'Executes the procedure named SomeProc and passes it 3 arguments. 
    
ThisDocument.ExecuteLine("Module1.SomeProc 1, 2, 3")
    'Same as previous example, but procedure name qualified
    'with module name. 
    
ThisDocument.ExecuteLine("UserForm1.Show")
    'Shows the form UserForm1. 
    
ThisDocument.ExecuteLine("Debug.Print ""some string""")
    'Prints "some string" to VBA's Immediate window. 
    
ThisDocument.ExecuteLine("Debug.Print Documents.Count")
    'Prints number of open documents to Immediate window. 
    
ThisDocument.ExecuteLine("ThisDocument.Save")
    'Tells ThisDocument to save itself.