ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Close w/o saving changes (https://www.excelbanter.com/excel-programming/431666-close-w-o-saving-changes.html)

Mark

Close w/o saving changes
 
Hi,
Im 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


Stefi

Close w/o saving changes
 
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,
Im 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


Mark

Close w/o saving changes
 
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,
Im 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


John

Close w/o saving changes
 
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,
Im 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


Mark

Close w/o saving changes
 
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,
Im 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


John

Close w/o saving changes
 
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,
Im 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


Mark

Close w/o saving changes
 
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,
Im 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



All times are GMT +1. The time now is 09:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com