Eval Method (ActiveX)

Evaluates an expression in VBA.

Supported platforms: Windows only

Signature

VBA:

object.Eval Expression
object

Type: Application

The object this method applies to.

Expression

Access: Input-only

Type: String

The expression to be evaluated.

Return Value (RetVal)

No return value.

Remarks

This method allows Automation clients to execute a line of VBA code in the context of the current project without creating modules and functions.

Examples

VBA:

Sub Example_Eval()
    ' This example shows how to can use Eval to run a VBA code fragment
    ' without having to create a Module or procedure.

    Dim VBACode As String
    
    ' Create VBA code fragment
    VBACode = "MsgBox ""Simple code fragment"""
    
    ' Use Eval method to evaluate the small VBA script
    Eval VBACode
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_Eval()
    ;; This example shows how to can use Eval to run a VBA code fragment
    ;; without having to create a Module or procedure.
    (setq acadObj (vlax-get-acad-object))
    
    ;; Create VBA code fragment
    (setq VBACode "MsgBox \"Simple code fragment\"")
    
    ;; Use Eval method to evaluate the small VBA script
    (vla-Eval acadObj VBACode)
)