How to Add Date and Time To File Name Using VBA in Excel

前端 未结 3 1752
你的背包
你的背包 2020-12-21 06:16

Thanks to Siddharth Rout at this Post I learned how to save a sheet to a new Worksheet. Now my question is how I can add Date and Time of file creation like:

3条回答
  •  借酒劲吻你
    2020-12-21 06:58

    I have the following working well but would like to reverse the order. File name first, date and time second. So far have not figured out a way.

    Sub SaveToLocations()
    ' Saves active file to current plus two other backup locations, appends system date and time in front of file name in backup locations.
    
        Dim datim As String
        datim = Format(CStr(Now), "yyyy_mm_dd_hh_mm_ss_")
    
        ActiveWorkbook.SaveCopyAs "I:\FilesBackup\" & datim & ActiveWorkbook.Name
        ActiveWorkbook.SaveCopyAs "E:\CS Docs\FilesBackupCS\" & datim & ActiveWorkbook.Name
        ActiveWorkbook.Save
    End Sub
    

提交回复
热议问题