VBA capture File SaveAs Event

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.
 
J

J.E. McGimpsey

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.
 
D

Dave Peterson

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
 

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