In Excel 2007 I have the following very simple code in VBA:
Public Type specType
sb As Long
End Type
Private Sub MyButton_Click()
Dim spec As specType
'...
End Sub
When the button is clicked, i get a "User-defined type not defined" Error on the "Dim spec As specType" line... why? Do I have to move my user defined types to a special location?
The Type statement can be used only at the module level. After you have declared a user-defined type by using the Type statement, you can declare a variable of that type anywhere within the scope of the declaration. Use Dim, Private, Public, ReDim, or Static to declare a variable of a user-defined type.
Object Required in Excel VBA. Object required is an error which is caused at run time when we have defined any variable which is not an object but we try to assign some values using a SET statement. This error is a run time error that arises for various reasons.
Turns out Types have to be defined before any functions in the module, otherwise they simply won't be recognized (without giving you an error).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With