Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 989
Default 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

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
close without saving calebjill Excel Discussion (Misc queries) 1 January 29th 09 11:16 PM
VBA - Close without saving changes PaulW Excel Discussion (Misc queries) 2 July 27th 06 01:22 PM
Close without saving LoveCandle[_32_] Excel Programming 3 June 26th 06 09:59 AM
Close without saving Brian Matlack[_54_] Excel Programming 5 February 8th 06 07:31 PM
Close without Saving In VBA Celtic_Avenger[_14_] Excel Programming 3 September 11th 04 11:04 PM


All times are GMT +1. The time now is 01:19 PM.

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"