This type of error occurs when an object is undefined:
A typical scenario is that the object itself is not created correctly when the object is defined, resulting in a "user-defined type undefined" error prompt at compile time.
This widget provides the following general methods for defining external objects:
Sub defines and references an external object () Word late-binding sample
Dim Wdapp as Object
Dim WD as Object
Dim TB as Object
Set Wdapp = CreateObject ("Word.Application") ' opens a Word application environment
Wdapp. Visible = True ' allows Word files to be visible
Set WD = Wdapp. Documents.Add ' Create a new Word document
Set TB = WD. Tables.add (WD. Range (0, 0), 3, 6)
' Add a 3-row 6-column form at the beginning of the document!!
End Sub
The associated library file is not referenced to cause such errors:
In particular, methods that refer to related controls in your code, but do not previously refer to corresponding library functions will cause such errors. For this we need to first join the support library for the control, and then we can reference the corresponding control in the edit.
Refer to the corresponding support library: in the VBA environment, click the "Tools"-> "Reference" item.
Then, in the Open References window, check the items and click OK to complete the Support library import operation.
In addition, for variables, Excel VBA takes two approaches, one weak definition, which allows the variable to be used directly without definition. The other is a strong definition, that is, the variable must be declared before use. If you want to switch between the two definitions, you can use the keyword "Option Explicit" to enter the strong definition declaration. This does not result in a "variable undefined" error prompt.