I have a problem in accessing excel 2010 via MS access 2010.
From access 2010, I want to get max row from my excel data.
Here is my code:
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
Dim lastRow As Long, i As Integer
MySheetPath = "C:\Users\myaccount\Desktop\LRLV\mydata.xlsx"
Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MySheetPath)
Xl.Visible = True
XlBook.Windows(1).Visible = True
Set XlSheet = XlBook.Worksheets(1)
With XlSheet
lastRow = .Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
End With
When I have no excel opened, everything is okay. But when I have 1 or more excel which has been opened the variabel "lastRow" always give me "Type mismatch" error. Now I need to know how to fix it. Thank you so much before.