i remember something about a way where i could avoid having to set objects of a type 'as…
- User
i remember something about a way where i could avoid having to set objects of a type 'as new bla' in vba. This way I could declare the variable more like an object, where i could go dim thing as stuff instead of ding thing as stuff + set thing as new stuff or dim thing as new stuff, entirely avouiding the new keyword. but i forget.
- Assistant
It sounds like you're recalling how, in VBA, you can work with existing objects without needing to use the
Newkeyword to instantiate them. Typically, when you declare an object variable that you intend to assign to an existing object rather than create a new one, you can write:Dim thing As SomeObjectTypeThen, you can set
thingto refer to an existing object of that type without using theNewkeyword:Set thing = ExistingObjectBy doing this, you avoid using
Newbecause you're not creating a new instance; instead, you're working with an object that already exists (perhaps returned from a function, part of a collection, or a built-in object in the application).However, you still need to use the
Setkeyword when assigning object references in VBA. The keyword is required to assign an object reference to a variable, distinguishing it from assigning a value to a standard (non-object) variable.