Run macro in one open workbook only
Why not just add your macro to the save event in that workbook
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'your macro
End Sub
'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Paul S" wrote in message
oups.com...
Hi All,
I'm just a noob to VBA so i need some help which may be obvious.
I need to run a macro when save / saveas is used within WorkbookX. got
that part worked out,
but it tries to run in other workbooks that are also open, which I
don't want it to, because it is referring to sheets that only exist in
WorkbookX. Here's the code from WorkbookX
Sub Workbook_Open()
Application.CommandBars("Standard").Controls("&Sav e").OnAction =
"MySave"
Application.CommandBars("Worksheet Menu
Bar").Controls("File").Controls("Save").OnAction = "MySave"
Application.CommandBars("Worksheet Menu
Bar").Controls("File").Controls("Save As...").OnAction = "MySaveAs"
End Sub
Sub Workbook_BeforeClose(Cancel As Boolean)
Application.CommandBars("Standard").Controls("&Sav e").OnAction = ""
Application.CommandBars("Worksheet Menu
Bar").Controls("File").Controls("Save").OnAction = ""
Application.CommandBars("Worksheet Menu
Bar").Controls("File").Controls("Save As...").OnAction = ""
End Sub
So how do I limit this working to just WorkbookX - while still allowing
the user to change WorkbookX's name using SaveAs?
thanks
Paul
|