Hi
I'm running excel from access and I can run the spreadsheet once and it works fine the next time I run it
I get runtime error 1004 method sheets of object _application failed and it debugs to this line of code
Set ws = xl.Sheets(1)
in this function
Private Function FindLastRow() As Single
Dim c As Object
Dim strAddress As String
Dim LastRow As Long
'This function returns the last row of the spreadsheet
'set the xl object
Set xl = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Exit Function
End If
'set the workbook
Set wb = xl.ActiveWorkbook
'set the worksheet
'Set ws = xl.ActiveSheet
Set ws = xl.Sheets(1)
'select the cell(A1)
xl.Range("A1").Select
'get the last row
Set c = xl.cells.Find(What:="*", SearchDirection:=xlPrevious, searchOrder:=xlByRows)
If Not c Is Nothing Then
strAddress = c.Address
Do
FindLastRow = c.Row
Loop While Not c Is Nothing And c.Address <> strAddress
End If
End Function
I'd appreciate any help
Thanks
Angie
I'm running excel from access and I can run the spreadsheet once and it works fine the next time I run it
I get runtime error 1004 method sheets of object _application failed and it debugs to this line of code
Set ws = xl.Sheets(1)
in this function
Private Function FindLastRow() As Single
Dim c As Object
Dim strAddress As String
Dim LastRow As Long
'This function returns the last row of the spreadsheet
'set the xl object
Set xl = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Exit Function
End If
'set the workbook
Set wb = xl.ActiveWorkbook
'set the worksheet
'Set ws = xl.ActiveSheet
Set ws = xl.Sheets(1)
'select the cell(A1)
xl.Range("A1").Select
'get the last row
Set c = xl.cells.Find(What:="*", SearchDirection:=xlPrevious, searchOrder:=xlByRows)
If Not c Is Nothing Then
strAddress = c.Address
Do
FindLastRow = c.Row
Loop While Not c Is Nothing And c.Address <> strAddress
End If
End Function
I'd appreciate any help
Thanks
Angie