Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Canceling Workbook_BeforeClose does not work

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Canceling Workbook_BeforeClose does not work

Your code worked fine for me.

--
Regards,
Tom Ogilvy



"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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Canceling Workbook_BeforeClose does not work

Thanks Mickey and Tom for trying out the code. I ran it from my home
computer last night and it also runs fine. I tried again on my work computer
this morning and it still does not work. Maybe something is fishy with my
Excel installation. The IT group has recently pushed out some Excel add-ins
that may be messing things up. Problem is, i've uninstalled them all and i
still have the issue.

Does anyone even know what sort of setting might be overwritten that would
prevent me from canceling Workbook_BeforeClose? I don't even know where to
begin. If i were home i would just re-install Excel but that's not so easy
at work.

Thanks.

"mickey" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Workbook_BeforeClose(Cancel As Boolean) - Cancel won't work gpmichal Setting up and Configuration of Excel 1 May 12th 09 02:33 AM
Canceling the rest of a Sub Rob Excel Programming 1 August 25th 06 04:29 PM
Workbook_BeforeClose: Cancel doesn't work sebt Excel Programming 2 February 23rd 06 10:50 AM
Workbook_BeforeClose doesn't work!!! [email protected] Excel Programming 3 October 17th 05 03:28 PM
Canceling a UserForm Eric W. Excel Programming 1 August 26th 03 06:56 PM


All times are GMT +1. The time now is 03:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"