View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
mickey mickey is offline
external usenet poster
 
Posts: 112
Default Canceling Workbook_BeforeClose does not work

Your code worked for me also, and I'm running XP (Excel 2003)

"jforstrom" wrote:

One of those bang your head against the wall ones...

FYI - ExcelXP, if it matters.

Everything i read says that setting Cancel = True in Workbook_BeforeClose
should prevent the workbook from actually closing, i.e. prevent the built-in
"Do you want to save?..." dialog from popping up. Am I wrong? I have a
blank workbook with only the following code in ThisWorkbook. If a change is
made and the user tries to close the workbook and then clicks CANCEL to my
home-grown dialog box, the built-in File-Save dialog box still pops up right
afterwards. What am i missing?? Thanks.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not Me.Saved Then
Msg = "Do you want to save the workbook?"
Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
Select Case Ans
Case vbYes
Me.Save
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
End Select
End If
End Sub