VBA capture File SaveAs Event

  • Thread starter Thread starter Linda Mcfarlane
  • Start date Start date
L

Linda Mcfarlane

In an Excel VBA application, when the user selects File
from the toolbar then File SaveAs, I want to capture that
event. If that's not possible, If I could at least
capture the event when they select File from the toolbar
that would help.
 
One way:

In the ThisWorkbook code module of your workbook:

Private Sub Workbook_Activate()
Application.CommandBars("Worksheet menu bar").Controls( _
"File").Controls("Save As...").OnAction = "mymacro"
End Sub

Private Sub Workbook_Deactivate()
Application.CommandBars("Worksheet menu bar").Controls( _
"File").Controls("Save As...").Reset
End Sub

where "mymacro" is a macro in a regular code module.
 
Another option might be to catch the SaveAs inside the workbook_beforesave
event.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

If SaveAsUI Then
MsgBox "using SaveAs"
'do what you want
Cancel = true 'stop that save!
End If

End Sub

You can read a lot more about events at Chip Pearson's site:
http://www.cpearson.com/excel/events.htm
 
Back
Top