PC Review


Reply
Thread Tools Rate Thread

Close w/o saving changes

 
 
Mark
Guest
Posts: n/a
 
      28th Jul 2009
Hi,
I’m trying to run a procedure from a workbook (ThisWorkbook), as follows:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Run "Personal.xls!EndIt", Cancel
End Sub

The code in Personal.xls (standard module) is:

Sub EndIt(Cancel As Boolean)
On Error GoTo Err_EndIt
Set fso = Nothing
Set shSeason = Nothing
If MsgBox("Do you want to save changes to this workbook?", vbYesNo,
Title:="Save LPM Workbook") = vbYes Then
ActiveWorkbook.Save
End If
Application.CommandBars("Ply").Enabled = True
Application.Caption = Empty
Exit_EndIt:
Exit Sub
Err_EndIt:
Call LogError(Err.Number, Err.Description, "EndIt(Cancel As Boolean)")
Resume Exit_EndIt
End Sub

I want to save the active workbook, if the User selects “Yes”, or not save
it, if the User selects “No”.
The save and close on “Yes” works correctly, but the close on “No” sends up
a MSO message box asking me if I want to save changes. How do I suppress the
MSO message box? Thanks.
Mark

 
Reply With Quote
 
 
 
 
Stefi
Guest
Posts: n/a
 
      28th Jul 2009
Try this:

If MsgBox("Do you want to save changes to this workbook?", vbYesNo, _
Title:="Save LPM Workbook") = vbYes Then
ActiveWorkbook.Close Savechanges:=True
Else
ActiveWorkbook.Close Savechanges:=False
End If

Regards,
Stefi


„Mark” ezt *rta:

> Hi,
> I’m trying to run a procedure from a workbook (ThisWorkbook), as follows:
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Run "Personal.xls!EndIt", Cancel
> End Sub
>
> The code in Personal.xls (standard module) is:
>
> Sub EndIt(Cancel As Boolean)
> On Error GoTo Err_EndIt
> Set fso = Nothing
> Set shSeason = Nothing
> If MsgBox("Do you want to save changes to this workbook?", vbYesNo,
> Title:="Save LPM Workbook") = vbYes Then
> ActiveWorkbook.Save
> End If
> Application.CommandBars("Ply").Enabled = True
> Application.Caption = Empty
> Exit_EndIt:
> Exit Sub
> Err_EndIt:
> Call LogError(Err.Number, Err.Description, "EndIt(Cancel As Boolean)")
> Resume Exit_EndIt
> End Sub
>
> I want to save the active workbook, if the User selects “Yes”, or not save
> it, if the User selects “No”.
> The save and close on “Yes” works correctly, but the close on “No” sends up
> a MSO message box asking me if I want to save changes. How do I suppress the
> MSO message box? Thanks.
> Mark
>

 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      28th Jul 2009
Thanks, Stefi. That does work, except that after you answer the message box,
the same message box appears again. I'd like to be able to do away with the
message box appearing a second time.
Mark

"Stefi" wrote:

> Try this:
>
> If MsgBox("Do you want to save changes to this workbook?", vbYesNo, _
> Title:="Save LPM Workbook") = vbYes Then
> ActiveWorkbook.Close Savechanges:=True
> Else
> ActiveWorkbook.Close Savechanges:=False
> End If
>
> Regards,
> Stefi
>
>
> „Mark” ezt *rta:
>
> > Hi,
> > I’m trying to run a procedure from a workbook (ThisWorkbook), as follows:
> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > Run "Personal.xls!EndIt", Cancel
> > End Sub
> >
> > The code in Personal.xls (standard module) is:
> >
> > Sub EndIt(Cancel As Boolean)
> > On Error GoTo Err_EndIt
> > Set fso = Nothing
> > Set shSeason = Nothing
> > If MsgBox("Do you want to save changes to this workbook?", vbYesNo,
> > Title:="Save LPM Workbook") = vbYes Then
> > ActiveWorkbook.Save
> > End If
> > Application.CommandBars("Ply").Enabled = True
> > Application.Caption = Empty
> > Exit_EndIt:
> > Exit Sub
> > Err_EndIt:
> > Call LogError(Err.Number, Err.Description, "EndIt(Cancel As Boolean)")
> > Resume Exit_EndIt
> > End Sub
> >
> > I want to save the active workbook, if the User selects “Yes”, or not save
> > it, if the User selects “No”.
> > The save and close on “Yes” works correctly, but the close on “No” sends up
> > a MSO message box asking me if I want to save changes. How do I suppress the
> > MSO message box? Thanks.
> > Mark
> >

 
Reply With Quote
 
john
Guest
Posts: n/a
 
      28th Jul 2009
mark try adding this line:

ThisWorkbook.Saved = True
--
jb


"Mark" wrote:

> Thanks, Stefi. That does work, except that after you answer the message box,
> the same message box appears again. I'd like to be able to do away with the
> message box appearing a second time.
> Mark
>
> "Stefi" wrote:
>
> > Try this:
> >
> > If MsgBox("Do you want to save changes to this workbook?", vbYesNo, _
> > Title:="Save LPM Workbook") = vbYes Then
> > ActiveWorkbook.Close Savechanges:=True
> > Else
> > ActiveWorkbook.Close Savechanges:=False
> > End If
> >
> > Regards,
> > Stefi
> >
> >
> > „Mark” ezt *rta:
> >
> > > Hi,
> > > I’m trying to run a procedure from a workbook (ThisWorkbook), as follows:
> > > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > > Run "Personal.xls!EndIt", Cancel
> > > End Sub
> > >
> > > The code in Personal.xls (standard module) is:
> > >
> > > Sub EndIt(Cancel As Boolean)
> > > On Error GoTo Err_EndIt
> > > Set fso = Nothing
> > > Set shSeason = Nothing
> > > If MsgBox("Do you want to save changes to this workbook?", vbYesNo,
> > > Title:="Save LPM Workbook") = vbYes Then
> > > ActiveWorkbook.Save
> > > End If
> > > Application.CommandBars("Ply").Enabled = True
> > > Application.Caption = Empty
> > > Exit_EndIt:
> > > Exit Sub
> > > Err_EndIt:
> > > Call LogError(Err.Number, Err.Description, "EndIt(Cancel As Boolean)")
> > > Resume Exit_EndIt
> > > End Sub
> > >
> > > I want to save the active workbook, if the User selects “Yes”, or not save
> > > it, if the User selects “No”.
> > > The save and close on “Yes” works correctly, but the close on “No” sends up
> > > a MSO message box asking me if I want to save changes. How do I suppress the
> > > MSO message box? Thanks.
> > > Mark
> > >

 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      28th Jul 2009
Thanks, John, but that didn't work either.
Mark

"john" wrote:

> mark try adding this line:
>
> ThisWorkbook.Saved = True
> --
> jb
>
>
> "Mark" wrote:
>
> > Thanks, Stefi. That does work, except that after you answer the message box,
> > the same message box appears again. I'd like to be able to do away with the
> > message box appearing a second time.
> > Mark
> >
> > "Stefi" wrote:
> >
> > > Try this:
> > >
> > > If MsgBox("Do you want to save changes to this workbook?", vbYesNo, _
> > > Title:="Save LPM Workbook") = vbYes Then
> > > ActiveWorkbook.Close Savechanges:=True
> > > Else
> > > ActiveWorkbook.Close Savechanges:=False
> > > End If
> > >
> > > Regards,
> > > Stefi
> > >
> > >
> > > „Mark” ezt *rta:
> > >
> > > > Hi,
> > > > I’m trying to run a procedure from a workbook (ThisWorkbook), as follows:
> > > > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > > > Run "Personal.xls!EndIt", Cancel
> > > > End Sub
> > > >
> > > > The code in Personal.xls (standard module) is:
> > > >
> > > > Sub EndIt(Cancel As Boolean)
> > > > On Error GoTo Err_EndIt
> > > > Set fso = Nothing
> > > > Set shSeason = Nothing
> > > > If MsgBox("Do you want to save changes to this workbook?", vbYesNo,
> > > > Title:="Save LPM Workbook") = vbYes Then
> > > > ActiveWorkbook.Save
> > > > End If
> > > > Application.CommandBars("Ply").Enabled = True
> > > > Application.Caption = Empty
> > > > Exit_EndIt:
> > > > Exit Sub
> > > > Err_EndIt:
> > > > Call LogError(Err.Number, Err.Description, "EndIt(Cancel As Boolean)")
> > > > Resume Exit_EndIt
> > > > End Sub
> > > >
> > > > I want to save the active workbook, if the User selects “Yes”, or not save
> > > > it, if the User selects “No”.
> > > > The save and close on “Yes” works correctly, but the close on “No” sends up
> > > > a MSO message box asking me if I want to save changes. How do I suppress the
> > > > MSO message box? Thanks.
> > > > Mark
> > > >

 
Reply With Quote
 
john
Guest
Posts: n/a
 
      28th Jul 2009
not sure where you have placed your code but it should work.

see if this helps - Taken from helpfile:

This example closes the workbook that contains the example code and discards
any changes to the workbook by setting the Saved property to True.

ThisWorkbook.Saved = True
ThisWorkbook.Close


--
jb


"Mark" wrote:

> Thanks, John, but that didn't work either.
> Mark
>
> "john" wrote:
>
> > mark try adding this line:
> >
> > ThisWorkbook.Saved = True
> > --
> > jb
> >
> >
> > "Mark" wrote:
> >
> > > Thanks, Stefi. That does work, except that after you answer the message box,
> > > the same message box appears again. I'd like to be able to do away with the
> > > message box appearing a second time.
> > > Mark
> > >
> > > "Stefi" wrote:
> > >
> > > > Try this:
> > > >
> > > > If MsgBox("Do you want to save changes to this workbook?", vbYesNo, _
> > > > Title:="Save LPM Workbook") = vbYes Then
> > > > ActiveWorkbook.Close Savechanges:=True
> > > > Else
> > > > ActiveWorkbook.Close Savechanges:=False
> > > > End If
> > > >
> > > > Regards,
> > > > Stefi
> > > >
> > > >
> > > > „Mark” ezt *rta:
> > > >
> > > > > Hi,
> > > > > I’m trying to run a procedure from a workbook (ThisWorkbook), as follows:
> > > > > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > > > > Run "Personal.xls!EndIt", Cancel
> > > > > End Sub
> > > > >
> > > > > The code in Personal.xls (standard module) is:
> > > > >
> > > > > Sub EndIt(Cancel As Boolean)
> > > > > On Error GoTo Err_EndIt
> > > > > Set fso = Nothing
> > > > > Set shSeason = Nothing
> > > > > If MsgBox("Do you want to save changes to this workbook?", vbYesNo,
> > > > > Title:="Save LPM Workbook") = vbYes Then
> > > > > ActiveWorkbook.Save
> > > > > End If
> > > > > Application.CommandBars("Ply").Enabled = True
> > > > > Application.Caption = Empty
> > > > > Exit_EndIt:
> > > > > Exit Sub
> > > > > Err_EndIt:
> > > > > Call LogError(Err.Number, Err.Description, "EndIt(Cancel As Boolean)")
> > > > > Resume Exit_EndIt
> > > > > End Sub
> > > > >
> > > > > I want to save the active workbook, if the User selects “Yes”, or not save
> > > > > it, if the User selects “No”.
> > > > > The save and close on “Yes” works correctly, but the close on “No” sends up
> > > > > a MSO message box asking me if I want to save changes. How do I suppress the
> > > > > MSO message box? Thanks.
> > > > > Mark
> > > > >

 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      28th Jul 2009
Hi John,
I'm putting the code in the workbook_beforeclose event right after the call
to Personal.xls. Unfortunately, it still doesn't work.
Mark

"john" wrote:

> not sure where you have placed your code but it should work.
>
> see if this helps - Taken from helpfile:
>
> This example closes the workbook that contains the example code and discards
> any changes to the workbook by setting the Saved property to True.
>
> ThisWorkbook.Saved = True
> ThisWorkbook.Close
>
>
> --
> jb
>
>
> "Mark" wrote:
>
> > Thanks, John, but that didn't work either.
> > Mark
> >
> > "john" wrote:
> >
> > > mark try adding this line:
> > >
> > > ThisWorkbook.Saved = True
> > > --
> > > jb
> > >
> > >
> > > "Mark" wrote:
> > >
> > > > Thanks, Stefi. That does work, except that after you answer the message box,
> > > > the same message box appears again. I'd like to be able to do away with the
> > > > message box appearing a second time.
> > > > Mark
> > > >
> > > > "Stefi" wrote:
> > > >
> > > > > Try this:
> > > > >
> > > > > If MsgBox("Do you want to save changes to this workbook?", vbYesNo, _
> > > > > Title:="Save LPM Workbook") = vbYes Then
> > > > > ActiveWorkbook.Close Savechanges:=True
> > > > > Else
> > > > > ActiveWorkbook.Close Savechanges:=False
> > > > > End If
> > > > >
> > > > > Regards,
> > > > > Stefi
> > > > >
> > > > >
> > > > > „Mark” ezt *rta:
> > > > >
> > > > > > Hi,
> > > > > > I’m trying to run a procedure from a workbook (ThisWorkbook), as follows:
> > > > > > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > > > > > Run "Personal.xls!EndIt", Cancel
> > > > > > End Sub
> > > > > >
> > > > > > The code in Personal.xls (standard module) is:
> > > > > >
> > > > > > Sub EndIt(Cancel As Boolean)
> > > > > > On Error GoTo Err_EndIt
> > > > > > Set fso = Nothing
> > > > > > Set shSeason = Nothing
> > > > > > If MsgBox("Do you want to save changes to this workbook?", vbYesNo,
> > > > > > Title:="Save LPM Workbook") = vbYes Then
> > > > > > ActiveWorkbook.Save
> > > > > > End If
> > > > > > Application.CommandBars("Ply").Enabled = True
> > > > > > Application.Caption = Empty
> > > > > > Exit_EndIt:
> > > > > > Exit Sub
> > > > > > Err_EndIt:
> > > > > > Call LogError(Err.Number, Err.Description, "EndIt(Cancel As Boolean)")
> > > > > > Resume Exit_EndIt
> > > > > > End Sub
> > > > > >
> > > > > > I want to save the active workbook, if the User selects “Yes”, or not save
> > > > > > it, if the User selects “No”.
> > > > > > The save and close on “Yes” works correctly, but the close on “No” sends up
> > > > > > a MSO message box asking me if I want to save changes. How do I suppress the
> > > > > > MSO message box? Thanks.
> > > > > > Mark
> > > > > >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
close without saving calebjill Microsoft Excel Misc 1 29th Jan 2009 11:16 PM
close w/o saving jatman Microsoft Excel Worksheet Functions 5 29th Feb 2008 02:52 PM
VBA - Close without saving changes =?Utf-8?B?UGF1bFc=?= Microsoft Excel Misc 2 27th Jul 2006 01:22 PM
Close without saving TRob Microsoft Access Forms 7 12th May 2004 04:04 AM
close w/o saving frs Microsoft Excel Misc 2 5th Mar 2004 02:30 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 PM.