我試過這段代碼,似乎它不工作。誰能告訴我爲什麼?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