我能够毫无错误地运行此代码,但目标略有不同。
根据以下链接中的代码,将其添加到 Do Events 部分下方。
Loop through all excel file in given folder
代码目标:
现状:
E.g文件存在于
中C:\用户\泰勒\桌面\测试
包含日期的新文件将保存在
中C:\用户\泰勒\桌面
码
Dim CellDate As String, fName As String
fName = Left(ActiveWorkbook.Name, (InStrRev(ActiveWorkbook.Name, ".", -1, vbTextCompare) - 1))
CellDate = ThisWorkbook.Worksheets("Sheet1").Range("H2")
CellDate = Format(Date, "YYYYMMDD")
ActiveWorkbook.SaveAs fName & "-" & CellDate, FileFormat:=xlOpenXMLWorkbookMacroEnabled
感谢帮助(:
答案 0 :(得分:1)
你试过吗
ActiveWorkbook.SaveAs myPath & fName & "-" & CellDate, FileFormat:=xlOpenXMLWorkbookMacroEnabled
如果文件夹选择的代码是按照链接的话,那么它的值将存储在myPath中。
假设“C:\ Users \ Tyler \ Desktop \ Test”是选中的文件夹。
注意:
来自链接的相关代码......
'Retrieve Target Folder Path From User
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
.Title = "Select A Target Folder"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
myPath = .SelectedItems(1) & "\"
End With