以相同名称保存文件但附加日期 - 引用单元格日期

Saving file as same name but attaching date - referencing cell date

我能够 运行 这段代码没有任何错误,但是给出了一个稍微不同的 objective。

将根据下面link中的代码添加到Do Events部分下方。

Loop through all excel file in given folder

Objective 代码:

现状:

E.g File exist in

C:\Users\Tyler\Desktop\Test

New file with date will be saved in

C:\Users\Tyler\Desktop

代码

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

感谢帮助 (:

你试过了吗

ActiveWorkbook.SaveAs myPath & fName & "-" & CellDate, FileFormat:=xlOpenXMLWorkbookMacroEnabled

如果您的文件夹选择代码符合 link,那么它的值将存储在 myPath 中。

假设 "C:\Users\Tyler\Desktop\Test" 是选定的文件夹。

注:

来自 link 的关联代码...

'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