Hi, this is my 1st post. I've checked several previous threads but am still at a loss to understand my problem.
I'm getting repeated Excel "Do you want to save the changes..." propmpts when closing the workbook, although the following (stripped down) code works ok when saving:
[vba]
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
'
' Code to check conditions
'
If Not Conditions_Met Then
If MsgBox("... Do you still wish to save?", vbYesNo) = vbNo Then
Cancel = True
Exit Sub
End If
End If
'
' Code for saving
'
End Sub
[/vba]
When closing I get the required "Do you want to save..." prompt as expected - no problem. If I click "Yes" the BeforeSave event fires and my code above runs. If I then select "No" to abort the save, I'd like the save to be cancelled and the workbook closed. Instead I get another "Do you want to save..." prompt.
I tried putting
[VBA]Me.Saved = True[/VBA]
before the Exit Sub but it made no difference. (It would, however, cause Excel to assume changes had been saved before closing, if a previous save was aborted. I don't really want this.)
Do I need to set a variable in the BeforeClose sub and somehow use that in the BeforeSave sub?
I'm using Excel 2003 SP2.
Thanks for any help.