VBA Error User-defined type not defined Error
VBA Error User-defined type not defined Error

How to fix User-defined type not defined error in VBA ?

User-defined type error message usually occurs when the VBA compiler cannot recognize a custom data type or class that you’ve used in your code. This can be caused by various reasons, including missing references, incorrect syntax, or a simple typo.

To solve this error, the first thing you need to do is to identify the source of the problem. Check your code carefully and make sure that all the custom data types or classes are properly defined and referenced. If you’re using external libraries or APIs, make sure that you’ve added the appropriate references to your VBA project.

If you’ve confirmed that all your data types and classes are defined and referenced correctly, you can try resetting the VBA environment. Close all instances of Excel and then reopen the workbook to clear any cached or corrupted data.

Another solution is to explicitly declare the custom data type or class in your code. This can be done by using the “Option Explicit” statement at the beginning of your module and then declaring the custom type/class using the “Type” or “Class” keyword.

Selecting the right References from the available reference list will solve this isssue. In this example, we show how to fix “User-defined type not defined” compile error when “Outlook” called in a statement.

  1. Go to Tools Menu -> Click References
  2. Scroll down and select (tick) “Microsoft Outlook 16.0 Object Library” from the Available References list.
  3. Click “Ok”

Now you will be able to run the code without

VBA User-defined type not defined Outlook
VBA User-defined type not defined Outlook