'クラスを使用する
Sub Test_ApplicationRun_Class()
    Dim cls As clsTest: Set cls = New clsTest
    
    Dim xlApp_App As Application:   Set xlApp_App = Application
    Dim xlApp_Obj As Object:        Set xlApp_Obj = Application
    Dim xlApp_Var As Variant:       Set xlApp_Var = Application
    
    cls.Num = 9999
    Application.Run "Test_Proc_Sub_Class", cls
    Debug.Print "Application", cls.Num  '9999
    
    cls.Num = 9999
    xlApp_App.Run "Test_Proc_Sub_Class", cls
    Debug.Print "xlApp_App", cls.Num '9999
    
    cls.Num = 9999
    xlApp_Obj.Run "Test_Proc_Sub_Class", cls
    Debug.Print "xlApp_Obj", cls.Num '8888
    
    cls.Num = 9999
    xlApp_Var.Run "Test_Proc_Sub_Class", cls
    Debug.Print "xlApp_Var", cls.Num '8888
End Sub

Sub Test_Proc_Sub_Class(ByVal cls As clsTest)
    cls.Num = 8888
End Sub

ソースコード(clsTest)

Option Explicit

Private num_ As Variant

Property Get Num()
    Let Num = num_
End Property

Property Let Num(n As Variant)
    Let num_ = n
End Property

結果

Application     8888 
xlApp_App      8888 
xlApp_Obj      8888 

VBAのApplication.Runで変数を参照渡しする方法
Tagged on: