Erik på kontoret
Erik på kontoret

Reputation: 81

Can a with-block variable be referenced by a keyword in VBA?

Is there a keyword for the with-block variable? If that keyword would be for example This, the following code would work:

With New myType
    .DoSomething
    DoSomethingElse "abc", This, 123
End With

Upvotes: 0

Views: 45

Answers (2)

DisplayName
DisplayName

Reputation: 13386

you could add the following Function to your MyType class

Public Function This() As MyType
    Set This = Me
End Function

so that your main code could exploit it as follows:

With New MyType
    .DoSomething
    DoSomethingElse "abc", .This, 123

End With

Upvotes: 3

VV5198722
VV5198722

Reputation: 374

I'm afraid such a keyword doesn't exist. In Visual Basic I have written an extension method .Myself for this. In VBA I don't know any solution. Of course you can use a local variable.

Set a = New mytype
a.DoSomething
DoSomethingElse "abc", a, 123

Upvotes: 1

Related Questions