我试过这段代码,似乎它不工作。谁能告诉我为什么?Excel VB循环文件夹并运行宏
Sub ProcessFiles()
Dim Filename, Pathname As String
Dim wb As Workbook
Pathname = ActiveWorkbook.Path & "C:\Macro\"
Filename = Dir(Pathname & "*.xls")
Do While Filename <> ""
Set wb = Workbooks.Open(Pathname & Filename)
DoWork wb
wb.Close SaveChanges:=True
Filename = Dir()
Loop
End Sub
Sub DoWork(wb As Workbook)
With wb
Range("A1").Select
ActiveCell.FormulaR1C1 = "Name"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Anil"
Range("A2").Select
End With
End Sub
[在多个excel文件上运行相同的excel宏](http:// stackoverflow。com/questions/14766238/run-same-excel-macro-on-multiple-excel-files) – brettdj 2013-02-09 05:34:55
答案已经在这个问题的原始文章中给出。 – peterm 2013-02-09 05:55:21