ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Prompt to save changes (https://www.excelbanter.com/excel-programming/328293-prompt-save-changes.html)

sanj

Prompt to save changes
 
Hi,

I tried to search for this answer, I have a routine that executes on

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
DeleteCM
End Sub

but before the Hidesheets and DeleteCM execute I would like to prompt the
user if they would like to save the changes, only if the select 'Yes' should
the Hidesheets and DeleteCM execute - any help is appreciated.

Regards.

Sanjay



Vasant Nanavati

Prompt to save changes
 
Something like (not fully error-tested):

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error GoTo ErrorHandler
Application.EnableEvents = False
iResponse = MsgBox("Do you want to save the changes you made to " _
& Name & "?", vbYesNoCancel + vbExclamation, "Microsoft Excel")
If iResponse = vbYes Then
HideSheets
DeleteCM
Save
Close
ElseIf iResponse = vbNo Then
Close False
Else
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

--

Vasant

"sanj" wrote in message
...
Hi,

I tried to search for this answer, I have a routine that executes on

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
DeleteCM
End Sub

but before the Hidesheets and DeleteCM execute I would like to prompt the
user if they would like to save the changes, only if the select 'Yes'

should
the Hidesheets and DeleteCM execute - any help is appreciated.

Regards.

Sanjay





Bob Phillips[_7_]

Prompt to save changes
 
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ans As Long
ans = MsgBox("Save changes (Y/N)?",vbYesNo)
If ans = vbYes Then
HideSheets
DeleteCM
End If
End Sub

--
HTH

Bob Phillips

"sanj" wrote in message
...
Hi,

I tried to search for this answer, I have a routine that executes on

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
DeleteCM
End Sub

but before the Hidesheets and DeleteCM execute I would like to prompt the
user if they would like to save the changes, only if the select 'Yes'

should
the Hidesheets and DeleteCM execute - any help is appreciated.

Regards.

Sanjay





Vasant Nanavati

Prompt to save changes
 
Hi Bob:

Won't this give rise to a duplicate save prompt (the built-in one)?

Regards,

Vasant

"Bob Phillips" wrote in message
...
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ans As Long
ans = MsgBox("Save changes (Y/N)?",vbYesNo)
If ans = vbYes Then
HideSheets
DeleteCM
End If
End Sub

--
HTH

Bob Phillips

"sanj" wrote in message
...
Hi,

I tried to search for this answer, I have a routine that executes on

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
DeleteCM
End Sub

but before the Hidesheets and DeleteCM execute I would like to prompt

the
user if they would like to save the changes, only if the select 'Yes'

should
the Hidesheets and DeleteCM execute - any help is appreciated.

Regards.

Sanjay







Charlie

Prompt to save changes
 
If MsgBox("Save Changes?", vbYesNo) = vbYes Then
HideSheets
DeleteCM
End If


"sanj" wrote:

Hi,

I tried to search for this answer, I have a routine that executes on

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
DeleteCM
End Sub

but before the Hidesheets and DeleteCM execute I would like to prompt the
user if they would like to save the changes, only if the select 'Yes' should
the Hidesheets and DeleteCM execute - any help is appreciated.

Regards.

Sanjay




sanj

Prompt to save changes
 
Thanks I will try it out!

Regards,

Sanjay


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Something like (not fully error-tested):

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error GoTo ErrorHandler
Application.EnableEvents = False
iResponse = MsgBox("Do you want to save the changes you made to " _
& Name & "?", vbYesNoCancel + vbExclamation, "Microsoft Excel")
If iResponse = vbYes Then
HideSheets
DeleteCM
Save
Close
ElseIf iResponse = vbNo Then
Close False
Else
End If
ErrorHandler:
Application.EnableEvents = True
End Sub

--

Vasant

"sanj" wrote in message
...
Hi,

I tried to search for this answer, I have a routine that executes on

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
DeleteCM
End Sub

but before the Hidesheets and DeleteCM execute I would like to prompt

the
user if they would like to save the changes, only if the select 'Yes'

should
the Hidesheets and DeleteCM execute - any help is appreciated.

Regards.

Sanjay







Bob Phillips[_7_]

Prompt to save changes
 
Hi Vasant,

I have no idea what Hidesheets or DeleteCm does, and the message is odd to
me, but I haven't added any save code as such.

Bob

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Hi Bob:

Won't this give rise to a duplicate save prompt (the built-in one)?

Regards,

Vasant

"Bob Phillips" wrote in message
...
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ans As Long
ans = MsgBox("Save changes (Y/N)?",vbYesNo)
If ans = vbYes Then
HideSheets
DeleteCM
End If
End Sub

--
HTH

Bob Phillips

"sanj" wrote in message
...
Hi,

I tried to search for this answer, I have a routine that executes on

Private Sub Workbook_BeforeClose(Cancel As Boolean)
HideSheets
DeleteCM
End Sub

but before the Hidesheets and DeleteCM execute I would like to prompt

the
user if they would like to save the changes, only if the select 'Yes'

should
the Hidesheets and DeleteCM execute - any help is appreciated.

Regards.

Sanjay










All times are GMT +1. The time now is 05:38 AM.

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