Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Can't delete sheets
Hi,
I'm trying to delete two sheets from a workbook that were added during a Workbook_Open event. In the close procedure I have the following code: Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.DisplayAlerts = False DoEvents On Error Resume Next If ActiveWorkbook.Worksheets(Sheets.Count).Name = "Summary" Then ActiveWorkbook.Worksheets("Summary").Visible = True ActiveWorkbook.Worksheets("Summary").Select ActiveWorkbook.Worksheets("Summary").Delete End If On Error GoTo 0 Worksheets(Sheets.Count).Visible = True Worksheets(Sheets.Count).Select Worksheets(Sheets.Count).Delete Application.Caption = Empty ThisWorkbook.Save ThisWorkbook.Close Application.DisplayAlerts = True Application.Quit End Sub The problem is that when I open the workbook, I get a '1004' error because the summary sheet already exists. I put a counter in the Workbook_Open procedure to verify that it was only firing once and message box at the tail end of the Workbook_BeforeClose procedure asking for the last sheet name, which was correct. So, why can't I delete these two sheets? Thanks. James |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming | |||
Macro to delete sheets and saves remaining file does not properly delete module | Excel Programming |