![]() |
Save vs SaveAs
Is there a way to detect in VB if the user did a Save Vs a SaveAs command.
Thank you. |
Save vs SaveAs
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. -- HTH, Barb Reinhardt "Sandy" wrote: Is there a way to detect in VB if the user did a Save Vs a SaveAs command. Thank you. |
Save vs SaveAs
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! -- Regards, Bill Renaud |
All times are GMT +1. The time now is 10:05 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com