I hope someone can help. I have tried eveything that is posted here and on other sites. I get the runtime error 462 a lot especially on the LRow line of code. But I have the Ghost Excel which I can't get rid of.
Below is a sampling of my code where I use code pointing to an Excel spreadsheet.
I have also tried the following for my IF selection and I still get the GHOST with it.
I have tried everything and am ready to pull my remaining hair out. Can anyone help?
Below is a sampling of my code where I use code pointing to an Excel spreadsheet.
Code:
Dim ExcelSheet As Object, XL As Object
Dim DB
Dim RSL
Dim X
Dim LRow As Integer
Set DB = CurrentDb()
Set RSL = DB.OpenRecordset("SELECT * from LABENTRY WHERE LLEVEL=1 ORDER BY LENTRY", dbOpenDynaset, dbReadOnly)
Set XL = CreateObject("Excel.Application") '
Set ExcelSheet = CreateObject("Excel.Sheet")
Set ExcelSheet = XL.Workbooks.Open("F:\payroll_time_sheet_BLANK.xls")
Do Until RSL.EOF
'
SName = RSL("LENTRY")
Counter = 4
LastCounter = 3
NCount = 5
'
XL.Worksheets(SName).Select
[b] LRow = XL.ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row [/b]
Do Until Counter = LRow
'
If (XL.ActiveSheet.Cells(Counter, 3).Value2 = "0" And _
XL.ActiveSheet.Cells(Counter, 1).Value2 = "0") Then
XL.ActiveSheet.Rows(Counter).Hidden = True
End If
RSL.MoveNext
Loop
ExcelSheet.Sheets(1).Select
ExcelSheet.Sheets(1).Cells(4, 3).Select
RSL.Close
ExcelSheet.Application.DisplayAlerts = False
ExcelSheet.SaveAs "F:\payroll_time_sheet_BLANK.xls"
ExcelSheet.Application.DisplayAlerts = True
'
On Error Resume Next
'
ExcelSheet.Application.Quit
'
DB.Close ' Release the object variable.
Set XL = Nothing
Set ExcelSheet = Nothing
Set RSL = Nothing
Set DB = Nothing
I have also tried the following for my IF selection and I still get the GHOST with it.
Code:
If (ExcelSheet.Sheets(SName).Cells(Counter, 3).Value2 = "0" And _
ExcelSheet.Sheets(SName).Cells(Counter, 1).Value2 = "0") Then
ExcelSheet.Sheets(SName).Rows(Counter).Hidden = True
End If
I have tried everything and am ready to pull my remaining hair out. Can anyone help?