Excel prompts user-defined types not defined what to do

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.