View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Patti[_2_] Patti[_2_] is offline
external usenet poster
 
Posts: 36
Default Before close - not always deleting sheet- WHY??

In the ThisWorkbook module I have:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
On Error Resume Next
ThisWorkbook.Sheets("SheetName1").Delete
ThisWorkbook.Sheets("SheetName2").Delete
On Error GoTo 0
Application.DisplayAlerts = True
End Sub

When the user closes the file, the following behavior occurs:

If user says NO to save changes, the sheets are deleted.
If user says YES to save changes, the sheets are deleted. (good so far....)

BUT, if the user makes a change, saves it, then says NO to the save prompt
when closing, the sheets are *not* deleted.

First of all, I don't understand why the user would get the "save changes?"
prompt right after saving on their own (which it does even if they do
nothing else). Second, I don't understand why the sheets aren't deleted in
this situation.

If anyone can explain, I would really appreciate it! (Using xl2002, no
other subs in ThisWorkbook module.)

Regards,

Patti