I am trying to read an excel file inside a access application using VBA. I have this code:
Dim xlApp As Excel.Application
Dim xlWrksht As Excel.worksheet
which I got from here:
Best way to read an Excel file into an Access database
but when I try to run it, I am getting error that user defines type is not define.
Should I add a reference to the application?
Is there any way that can do it without adding a reference to my application?
Edit 1
After adding reference to the code, Now I have this code:
Dim excelApp As Excel.Application
Dim workbook As Excel.workbook
Dim Worksheet As Excel.Worksheet
Set excelApp = CreateObject("Excel.application")
Set workbook = excelApp.Open(InputFileName)
Set Worksheet = workbook.Worksheets(1)
But now I am getting error on line:
Set workbook = excelApp.Open(InputFileName)
as the excelApp doesn't have any method called Open. Should I add any other reference?