Delete Excel Tabs

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!
 
E

egerds

Klatuu said:
oExcel.Worksheets("Closed1").Delete
or
oExcel.Worksheets(3).Delete

How would you copy the format from row example 2 and paste format to
the rows that are not empty? (Results from a query have been
transferspreedsheet to a template)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top