D
David
Hello all,
I am trying to open this doc, and delete a tab (worksheet). Can someone
please help me?
Dim oExcel As Object, oSheet As Object
Set oExcel = CreateObject("Excel.Application")
oExcel.Workbooks.Open "C:\Book1.xls"
'CODE here to delete sheets(3), titled Closed1
oExcel.ActiveWorkbook.Save
oExcel.ActiveWorkbook.Close
oExcel.Quit
Set oSheet = Nothing
Set oExcel = Nothing
This is what I've tried (but it fails)
oExcel.ActiveWorkbook.Worksheets("Closed1").Select
ActiveWindow.SelectedSheets.Delete
'***************************************
oExcel.ActiveWorkbook.Worksheets(3).Select
ActiveWindow.SelectedSheets.Delete
'***************************************
With oExcel.Application.Workbook
' .Visible = False
' .Workbooks.Open MyExcelFile
' .ActiveWorkbook.Application.DisplayAlerts = False
.ActiveWorkbook.Sheets(3).Delete
' .ActiveWorkbook.Save
' .ActiveWorkbook.SaveAs MyExcelFile
' .ActiveWorkbook.Application.DisplayAlerts = True
' .Workbooks.Application.Quit
End With
'***************************************
' Do While objXLBook.Worksheets.Count > 2
' objXLApp.Worksheets(objXLApp.Worksheets.Count).Delete
' MsgBox "After delete"
' MsgBox objXLBook.Worksheets.Count
' Loop
' Set objxlSheet = objXLBook.ActiveSheet
'***************************************
' If objXLBook.Worksheets.Count = 3 Then
' objXLApp.Worksheets(objXLApp.Worksheets.Count).Delete
'End If
'***************************************
HUGE PROPS to Dave Patrick MVP and RoyVidar for helping me understand some
of the basics with Excel automation!
I am trying to open this doc, and delete a tab (worksheet). Can someone
please help me?
Dim oExcel As Object, oSheet As Object
Set oExcel = CreateObject("Excel.Application")
oExcel.Workbooks.Open "C:\Book1.xls"
'CODE here to delete sheets(3), titled Closed1
oExcel.ActiveWorkbook.Save
oExcel.ActiveWorkbook.Close
oExcel.Quit
Set oSheet = Nothing
Set oExcel = Nothing
This is what I've tried (but it fails)
oExcel.ActiveWorkbook.Worksheets("Closed1").Select
ActiveWindow.SelectedSheets.Delete
'***************************************
oExcel.ActiveWorkbook.Worksheets(3).Select
ActiveWindow.SelectedSheets.Delete
'***************************************
With oExcel.Application.Workbook
' .Visible = False
' .Workbooks.Open MyExcelFile
' .ActiveWorkbook.Application.DisplayAlerts = False
.ActiveWorkbook.Sheets(3).Delete
' .ActiveWorkbook.Save
' .ActiveWorkbook.SaveAs MyExcelFile
' .ActiveWorkbook.Application.DisplayAlerts = True
' .Workbooks.Application.Quit
End With
'***************************************
' Do While objXLBook.Worksheets.Count > 2
' objXLApp.Worksheets(objXLApp.Worksheets.Count).Delete
' MsgBox "After delete"
' MsgBox objXLBook.Worksheets.Count
' Loop
' Set objxlSheet = objXLBook.ActiveSheet
'***************************************
' If objXLBook.Worksheets.Count = 3 Then
' objXLApp.Worksheets(objXLApp.Worksheets.Count).Delete
'End If
'***************************************
HUGE PROPS to Dave Patrick MVP and RoyVidar for helping me understand some
of the basics with Excel automation!