I am trying to edit an Excel file from MS Access without using Excel as a reference. I found an answer in this question that helps with this problem. Instead of using references to Excel, I use Objects. This seems to work for the most part, but I don't get all the functions I need from Excel in order to count the rows on a table. A snippet of my code is as follows:
Dim xlBook As Object
Dim xlApp As Object
Dim xlSht As Object
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Some\Location.xlsx")
Set xlSht = xlBook.Sheets("SomeSheet")
tableRows = xlSht.Cells(xlSht.Rows.Count, 2).End(xlUp).Row
I get an error on the tableRows = xlSht... line which reads:
Run-time error '1004':
Application-defined or object-defined error
I've tried numerous different ways of fixing this problem, such as rewriting the line, changing the sheetnames. I can't seem to find any documentation on this scenario. I'd appreciate any help.
activesheet.cells(activesheet.rows.count, 2).end(xlup).rowI've had the same problem more then once, referencing not to the variables you've set, but directly to the object fixed it for me Otherwise try something asactiveworkbook.sheet("Somesheet").cells(activeworkbook.sheet("Somesheet".rows.count, 2).end(xlup).rowI know it's not pretty, but it works. At least it did for mexlUpwith-4162??xlUpinto the VBE Immediate window - this will return the number you need.