Sub BatchApplyMacro()
Dim folderPath As String
Dim fileName As String
Dim targetWB As Workbook
Dim sourceWB As Workbook
Set sourceWB = ThisWorkbook '
当前含宏的xlsm文件
folderPath = 'D:\12\' ' 修改为实际路径
fileName = Dir(folderPath & '*.xls') '
匹配所有xls文件
Do While fileName <> ''
If fileName <> sourceWB.Name
Then ' 排除自身文件
Set targetWB =
Workbooks.Open(folderPath & fileName)
Application.Run '''
& sourceWB.Name & ''!Macro1' ' 替换为实际宏名
targetWB.Close
SaveChanges:=True
End If
fileName = Dir()
Loop
End Sub
End Sub
