P
Perry
I tried to delete all the Excel worksheets from within Access except the
first sheet but was unsuccessful. This is the code.
Sub test1()
Dim oXL, wk, sht1, cnt, ptr
Set oXL = CreateObject("Excel.Application")
Set wk = oXL.workbooks.Open(CurrentProject.Path & "\POReport#2.xls")
ptr = wk.sheets.Count
Debug.Print "Before count:" & ptr
For ptr = 2 To ptr
wk.worksheets(ptr).Delete
Next ptr
Debug.Print "After count:" & wk.sheets.Count
wk.Close
Set oXL = Nothing
End Sub
Thank you for the help.
first sheet but was unsuccessful. This is the code.
Sub test1()
Dim oXL, wk, sht1, cnt, ptr
Set oXL = CreateObject("Excel.Application")
Set wk = oXL.workbooks.Open(CurrentProject.Path & "\POReport#2.xls")
ptr = wk.sheets.Count
Debug.Print "Before count:" & ptr
For ptr = 2 To ptr
wk.worksheets(ptr).Delete
Next ptr
Debug.Print "After count:" & wk.sheets.Count
wk.Close
Set oXL = Nothing
End Sub
Thank you for the help.