vba - VarType for user defined type -
i have user-defined objects in vba code , wondering if there way check object type is. thing like
dim myobject variant set myobject= new employee if(myobject istype employee) else else
i thinking vartype() function, apparently won't work user defined types. there else can use?
there 2 possibilities so. following code should explain everything. see additional comments inside:
sub qtest() dim myobject variant set myobject = new employee 'return results immediate debug.print typename(myobject) '>> return class name debug.print typeof myobject employee '>>will return true 'using 'if statements', both return true if typename(myobject) = "employee" msgbox "ok" end if if typeof myobject employee msgbox "ok" end if end sub
Comments
Post a Comment