There are two steps to creating an object variable. First you must declare the object variable. Then you must assign a valid reference to the object variable using the Set statement. Similarly, a With...End With block must be initialized by executing the With statement entry point. This error has the following causes and solutions:
Specify or respecify a reference for the object variable. For example, if the Set statement is omitted in the following code, an error would be generated on the reference to MyObject
:
Dim MyObject As Object ' Create object variable.
Set MyObject = Sheets(1) ' Create valid object reference.
MyCount = MyObject.Count ' Assign Count value to MyCount.
Set MyObject = Nothing ' Release the object.
MyCount = MyObject.Count ' Make a reference to a released object.
Respecify a reference for the object variable. For example, use a new Set statement to set a new reference to the object.
Select the object library in the Add References dialog box.
Don't jump into a With block. Make sure the block is initialized by executing the With statement entry point.
The With block must be initialized by executing the With statement.
For additional information, select the item in question and press F1 (in Windows) or HELP (on the Macintosh).