ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Private Sub Workbook_BeforeSave (https://www.excelbanter.com/excel-programming/430124-private-sub-workbook_beforesave.html)

Fan924

Private Sub Workbook_BeforeSave
 
I am using this to run macros before and after a save event. Save &
SaveAs do the same thing. Can I have a second routine that does a Save
without asking for file and permission to overwrite?
SaveAs would be as below. TIA
____________________________________________

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
On Error GoTo PrintingOver
Application.EnableEvents = False
Call Workbook_2
Dim varResponse As Variant
varResponse = Application.GetSaveAsFilename( _
FileFilter:="Microsoft Excel Workbook (*.xls), *.xls")
If varResponse = False Then
'do nothing except exit
ElseIf varResponse = Me.FullName Then
MsgBox "Please save under a different name. "
Else
ThisWorkbook.SaveAs varResponse
End If

Call Workbook_2
PrintingOver:
Application.EnableEvents = True
Cancel = True
End Sub
-----------
by Jim Cone


Fan924

Private Sub Workbook_BeforeSave
 
How can I tell if the Save or SaveAs button was pushed?

Fan924

Private Sub Workbook_BeforeSave
 
Also, how do I detect if it is just a regular Save or if it is closing
the workbook and trying to save? How do I detect it is closing?



All times are GMT +1. The time now is 06:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com