尝试自动更新多个Excel文件。
(我可能遇到了错误的文件路径调用)
我的代码:
Sub UpdateFiles()
MyDir = Application.ThisWorkbook.Path
DataDir = MyDir & "\folder1\"
ChDir (DataDir)
Nextfile = Dir("*.xlsx")
While Nextfile <> ""
Workbooks.Open (Nextfile)
Workbooks(Nextfile).Sheets("sheet1").Range("F22") = "Major"
Workbooks(Nextfile).Save
Workbooks(Nextfile).Close
Nextfile = Dir()
Wend
End Sub
希望sheet1上单元格F22中的数据读取为“主要”
该模式"*.xls*"
可同时打开.xlsx和.xlsm文件以及其他.xls文件
Sub UpdateFiles()
MyDir = Application.ThisWorkbook.Path
DataDir = MyDir & "\folder1\"
Nextfile = Dir("*.xls*")
While Nextfile <> ""
With Workbooks.Open (Nextfile)
.Sheets("sheet1").Range("F22") = "Major"
.Save
.Close
End With
Nextfile = Dir()
Wend
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句