e.J*_*mes 5 vba class creation object
我正在寻找在VBA中创建和返回新类对象的正确方法.
我熟悉以下用于返回新Type变量的模式(由value返回):
Public Type Foo
x as Integer
y as Integer
End Type
Public Function NewFoo() as Foo
NewFoo.x = 4
NewFoo.y = 2
End Function
Run Code Online (Sandbox Code Playgroud)
新的Class对象(通过引用返回)的等效语法是什么?
Public Function NewMyClass() As MyClass
''// ...?
End Function
Run Code Online (Sandbox Code Playgroud)
obe*_*eak 10
如果要在VBA中返回Object,则必须将其设置为Method name
Public Function NewMyClass() As MyClass
Set NewMyClass = CreateObject("Some.MyClass");
End Function
Run Code Online (Sandbox Code Playgroud)