这是我的情况:我有工作簿" MyWorkbook"打开,使用名为" MyMacro"的宏,设置为按下按钮运行,我下载后打开一个名为" Analysis.xls"的文件。
有没有办法制作" MyMacro"每当我打开一个名为" Analysis.xls"无需单击按钮或手动调用宏进行操作?
答案 0 :(得分:1)
这应该可以解决问题(在MyWorkbook中的类模块或ThisWorkbook中执行此操作)...
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