LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default saving option

I'm using the following code for saving on closing.
But, when I click Yes to save changes it's not saving it.
Could anybody help?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim logReadOnly As Boolean
'Turn off events to prevent unwanted loops
Application.EnableEvents = False
logReadOnly = False
'Evaluate if workbook is saved and emulate default propmts
With ThisWorkbook
If Not .Saved Then
Select Case MsgBox("Do you want to save the changes you made to
'" & .Name & "'?", _
vbYesNoCancel + vbExclamation)
Case Is = vbYes
'Call customized save routine
If ActiveWorkbook.ReadOnly Then
logReadOnly = True
MsgBox ("The Application is read-only. You cannot save
changes.")
Else
Call CustomSave
End If
Case Is = vbNo
'Do not save
logReadOnly = True
Case Is = vbCancel
'Set up procedure to cancel close
Cancel = True
End Select
End If

'If Cancel was clicked, turn events back on and cancel close,
'otherwise close the workbook without saving further changes
If Not Cancel = True Then
.Saved = True
Application.EnableEvents = True
If logReadOnly Then
.Close savechanges:=False
Else
.Close savechanges:=True
End If
Else
Application.EnableEvents = True
End If
End With

End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'Turn off events to prevent unwanted loops
Application.EnableEvents = False

'Call customized save routine and set workbook's saved property to true
'(To cancel regular saving)
Call CustomSave(SaveAsUI)
Cancel = True

'Turn events back on an set saved property to true
Application.EnableEvents = True
ThisWorkbook.Saved = True
End Sub
 
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
Dont have secondary axis option listed in Series Option Venus Charts and Charting in Excel 3 February 23rd 10 07:30 PM
Saving changes to option to apply all the time. Stuart A Excel Discussion (Misc queries) 1 November 12th 09 11:19 AM
preserve formatting option in pivot table option dialog box Dave F Excel Discussion (Misc queries) 4 May 8th 08 07:25 PM
quit without saving option [email protected] Excel Programming 1 January 5th 05 03:38 PM
Option Commands (Option Explicit / Option Base etc) - Scope Alan Excel Programming 8 November 1st 04 02:22 AM


All times are GMT +1. The time now is 05:37 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"