尝试自动更新多个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
希望工作表1的单元格F22中的数据读取“主要”
答案 0 :(得分:0)
"*.xls*"
模式可同时打开 .xlsx 和 .xlsm 文件以及 .xls < / strong>文件
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