RunMacro Method (ActiveX)

Runs a VBA macro from the Application object.

Supported platforms: Windows only

Signature

VBA:

object.RunMacro MacroPath
object

Type: Application

The object this method applies to.

MacroPath

Access: Input-only

Type: String

A string representing the calling sequence of the macro to run. The calling sequence must have the following syntax, where [] represent optional parameters:

[Filename.dvb.][ProjectName.][ModuleName.]MacroName
Note: If Filename.dvb is followed by ProjectName, separate the names with an exclamation point instead of a period, as in the following example:
Filename.dvb!ProjectName

The Filename.dvb specified will be loaded if it is not already loaded. If the path to the Filename.dvb is not specified, the AutoCAD search path is searched to locate the file. If ProjectName is not specified, all currently loaded projects are searched to locate the macro.

Return Value (RetVal)

No return value.

Remarks

To associate a macro with a popup menu or toolbar item, use the Macro property.

Examples

VBA:

Sub Example_RunMacro()
    ' This example loads a DVB file and runs a macro
    ' contained in the file using the RunMacro method.
    '
    ' This example uses a DVB file named drawline.dvb.
    ' You should change the example to use a file on your computer.
    '
    ' * Note: If you open a DVB file and then run the example to load it, there will be an error
    ' when the DVB file is unloaded.

    Dim FileName As String
    
    FileName = "c:\drawline.dvb"
    
    ' Load a sample VBA project DVB file
    LoadDVB FileName
    
    ' Run the drawline sample macro
    RunMacro "Module1.Drawline"
    
    ' Unload the drawline VBA project DVB file now that we are done
    UnloadDVB FileName
    
    MsgBox "The DVB file has been run!"

End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_RunMacro()
    ;; This example loads a DVB file and runs a macro
    ;; contained in the file using the RunMacro method.
    ;;
    ;; This example uses a DVB file named drawline.dvb.
    ;; You should change the example to use a file on your computer.
    ;;
    ;; * Note: If you open a DVB file and then run the example to load it, there will be an error
    ;; when the DVB file is unloaded.
    (setq acadObj (vlax-get-acad-object))

    (setq fileName (findfile ".\\Sample\\VBA\\drawline.dvb"))
    
    ;; Load a sample VBA project DVB file
    (vla-LoadDVB acadObj fileName)
    
    ;; Run the drawline sample macro
    (vla-RunMacro acadObj "Module1.Drawline")
    
    ;; Unload the drawline VBA project DVB file now that we are done
    (vla-UnloadDVB acadObj fileName)
    
    (alert "The DVB file has been run!")
)