Need help with BeforeSave event

G

Guest

Hi,

I have code in the BeforeSave to 'suggest' a filename to save as but the
user needs to be able to change the 'suggestion' before saving. I'm using
Application.GetSaveAsFilename to suggest the filename. When
ThisWorkbook.SaveAs SaveAsFileName is executed, it fires the BeforeSave event
again. Is there anyway a better way to do what I'm attempting here?


If SaveAsUI = True Then
' displays SaveAs dialog box with default filename. Returns
SaveAsFileName
SaveAsFileName = Application.GetSaveAsFilename(PMFileName, "Microsoft
Office Excel Workbook (*.xls), *.xls")
' if user clicked Cancel then SaveAsFileName = False
If SaveAsFileName = "False" Then
Cancel = True
Exit Sub
Else
ThisWorkbook.SaveAs SaveAsFileName
Cancel = True
End If
End If
 
G

Guest

Temporarily disable events with "Application.EnableEvents=False". Then reset
to True as follows:

If SaveAsFileName = "False" Then
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
Exit Sub
Else
Application.EnableEvents = False
ThisWorkbook.SaveAs SaveAsFileName
Application.EnableEvents = True
Cancel = True '<<<===I think this is unnecessary; suggest delete
(but test)
End If
End If
 
T

Tom Ogilvy

Cancel = true
means to not perform the action that triggered the BeforeSave Event, so it
is certainly necessary.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top