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


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