What does the keyword Set actually do in VBA?

前端 未结 7 2422
既然无缘
既然无缘 2020-11-22 04:26

Hopefully an easy question, but I\'d quite like a technical answer to this!

What\'s the difference between:

i = 4

and



        
7条回答
  •  青春惊慌失措
    2020-11-22 04:49

    In your case, it will produce an error. :-)

    Set assigns an object reference. For all other assignments the (implicit, optional, and little-used) Let statement is correct:

    Set object = New SomeObject
    Set object = FunctionReturningAnObjectRef(SomeArgument)
    
    Let i = 0
    Let i = FunctionReturningAValue(SomeArgument)
    
    ' or, more commonly '
    
    i = 0
    i = FunctionReturningAValue(SomeArgument)
    

提交回复
热议问题