Home » Visual Stuio » Solved: “User-defined type not defined” error at declarations of Excel variables (VBA)

Solved: “User-defined type not defined” error at declarations of Excel variables (VBA)

You may face “User-defined type not defined” error as you declare Excel specific variables. This issue is little tricky.

Your code may be like this:

Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlSheet As Excel.Worksheet
You are missing a reference

Solution

This error occurs because of the missing reference. You should add Excel reference before declaring Excel objects. To get rid of this error:

  • Go to “Tools > References” in VBA compiler
  • Add “Microsoft Excel 14.0 Object Library”

    Adding Excel Object Library as a reference

Ned Sahin

Blogger for 20 years. Former Microsoft Engineer. Author of six books. I love creating helpful content and sharing with the world. Reach me out for any questions or feedback.

1 thought on “Solved: “User-defined type not defined” error at declarations of Excel variables (VBA)”

Leave a Comment