Save vs SaveAs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to detect in VB if the user did a Save Vs a SaveAs command.

Thank you.
 
There is.

Put this in the "ThisWorkbook" module

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
MsgBox ("You did a SAVEAS")
Else
MsgBox ("You did a SAVE")
End If

End Sub

I've not used it much so had to play a bit. I'm not sure how the CANCEL
works.
 
Barb wrote:
<< I'm not sure how the CANCEL works.>>

From the Excel topic for the Workbook_BeforeSave event:
"If the event procedure sets this argument to True, the workbook isn't
saved when the procedure is finished."

Most events have this Cancel argument. It is used by the VBA programmer
(you) to tell Excel whether you want it to go ahead and run the normal
routine after your event handler has finished or not. Usually, you
simply want to intercept the function, insert some customized activity
of some sort, then continue with the normal Excel action. But sometimes,
you decide that you want to skip the rest of the default Excel behavior
for some reason. For example, you might want to skip Saving the
workbook, if the user had not selected the "SaveAs" command to give the
workbook a new name after making some changes. In this case, in the Else
part of the If statement, you would set Cancel to TRUE after displaying
the message box. This would force the user to use SaveAs and rename the
workbook while saving it. You would want to be sure to display a very
clear message that the workbook has NOT been saved!
 

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

Back
Top