Reputation: 1
Here's my situation: I have workbook "MyWorkbook" open, with a macro called "MyMacro", which is set to run on a button click, ,which I user after I download and open a file called "Analysis.xls".
Is there a way to make "MyMacro" run whenever I open a file called "Analysis.xls" without having to click a button or manually calling the macro into action?
Upvotes: 0
Views: 746
Reputation: 4161
This should do the trick (do this in a Class Module or ThisWorkbook in MyWorkbook)...
Private WithEvents app As Application
Private Sub Workbook_Open()
Set app = Application
End Sub
Private Sub app_WorkbookOpen(ByVal Wb as Workbook)
If Wb.Name = "Analysis.xls" Then
'run your macro here
End If
End Sub
Upvotes: 1