ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA capture File SaveAs Event (https://www.excelbanter.com/excel-programming/277175-vba-capture-file-saveas-event.html)

Linda Mcfarlane

VBA capture File SaveAs Event
 
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.E. McGimpsey

VBA capture File SaveAs Event
 
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.


In article ,
"Linda Mcfarlane" wrote:

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.


Dave Peterson[_3_]

VBA capture File SaveAs Event
 
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

Linda Mcfarlane wrote:

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.


--

Dave Peterson



All times are GMT +1. The time now is 11:58 AM.

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