Thread: saving option
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
ALEX ALEX is offline
external usenet poster
 
Posts: 493
Default saving option

Thanks, Jim.
How could I make it to save on closing if the user chooses Yes (to save)?
I cannot see what's interrupting it.

I've includede the "CustomSave" in the previous post.

"Jim Cone" wrote:

Alex,

Yes, it does not save the workbook.
However, it calls another sub "CustomSave",which I assume is
supposed to contain the code to save the workbook.
The "CustomSave" code is not shown in your post.

Jim Cone
San Francisco, USA


"Alex"

wrote in message

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