After Save - 1 more question
Thanks Bob. Can I ask a follow up? The code you have works great. I have
'before save' code and 'after save' code executing when the user hits Save
ir SaveAs.
But, if the user makes some changes, and selects Close, Excel prompts if you
want to save changes. In that case, I would only want the 'before save'
event to trigger. Is that possible? Thanks!
"Bob Phillips" wrote in message
...
It will, but the SaveAsUI argument will be true in that case so you can
test
for it
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim sFile
Application.EnableEvents = False
'<Optional - this would be before save code
Cancel = True
If SaveAsUI Then
sFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
If sFile < False Then
ThisWorkbook.SaveAs sFile
End If
Else
ThisWorkbook.Save
End If
'<Optional - this would be after save code
Application.EnableEvents = True
End Sub
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Steph" wrote in message
...
Thanks Tom. One more question -
What if the user selects Save As? Does that throw a monkey wrench in
the
code?
"Tom Ogilvy" wrote in message
...
That would be the basic approach.
--
Regards,
Tom Ogilvy
"Steph" wrote in message
...
Thanks for all of your help. Just to confirm - by combining the
suggestions
of your posts, is the below code the proper way to perform the After
Save
Event? Thanks!
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
'<Optional - this would be before save code
application.enableevents = false
ThisWorkbook.Save
application.enableevents = true
'<Optional - this would be after save code
End Sub
|