Why does the following not delete the listed sheets in excel?
Private Sub cmdbtn_crewebbasexcgra_Click()
Dim xlSheet As Object, myfield As Variant, xlApp As Object, xlWork As Object, Strfile As String
Dim MyDb As Database, MyQuery As QueryDef, strSQL As String
Dim objXLBook As Excel.Workbook
Dim objXLSheet As Excel.Worksheet
Dim Response
Strfile = "c:\Documents and Settings\Ice Rhino\My Documents\Work Related\D2KLite\WebGraphs.xls"
Set xlApp = CreateObject("Excel.Application")
Set xlWork = xlApp.Workbooks.Open(Strfile)
Set xlSheet = xlWork.Sheets("Date_Info")
myfield = Me!txt_dateheader
xlSheet.Cells(1, 1).Value = myfield
xlWork.Worksheets(4).Delete
xlWork.Worksheets(5).Delete
xlWork.Worksheets(6).Delete
xlWork.Worksheets(7).Delete
xlWork.Save
xlApp.Quit
Set xlSheet = Nothing
Set xlApp = Nothing
Set xlWork = Nothing
Anybody got any ideas?
IR
Private Sub cmdbtn_crewebbasexcgra_Click()
Dim xlSheet As Object, myfield As Variant, xlApp As Object, xlWork As Object, Strfile As String
Dim MyDb As Database, MyQuery As QueryDef, strSQL As String
Dim objXLBook As Excel.Workbook
Dim objXLSheet As Excel.Worksheet
Dim Response
Strfile = "c:\Documents and Settings\Ice Rhino\My Documents\Work Related\D2KLite\WebGraphs.xls"
Set xlApp = CreateObject("Excel.Application")
Set xlWork = xlApp.Workbooks.Open(Strfile)
Set xlSheet = xlWork.Sheets("Date_Info")
myfield = Me!txt_dateheader
xlSheet.Cells(1, 1).Value = myfield
xlWork.Worksheets(4).Delete
xlWork.Worksheets(5).Delete
xlWork.Worksheets(6).Delete
xlWork.Worksheets(7).Delete
xlWork.Save
xlApp.Quit
Set xlSheet = Nothing
Set xlApp = Nothing
Set xlWork = Nothing
Anybody got any ideas?
IR