简体   繁体   中英

Save Macro-enabled workbook as "filename" + Current Date using VBA

I am trying to find out if it is possible to write VBA to save a file that I have open as "filename" (in this case "PO_Cancellation_Issues - ") + the current date? So for today it would save as "PO_Cancellation_Issues - 02192018". I would be open to any date format that saves mmddyyyy.

Thanks.

How about the following:

Sub foo()
'FileExtStr = ".xlsb": FileFormatNum = 50
'FileExtStr = ".xlsx": FileFormatNum = 51
'FileExtStr = ".xlsm": FileFormatNum = 52
'FileExtStr = ".csv": FileFormatNum = 6
'FileExtStr = ".txt": FileFormatNum = -4158
'FileExtStr = ".prn": FileFormatNum = 36

FileFormatNum = 51
TempFilePath = Application.DefaultFilePath & "\"
Filename = "PO_Cancellation_Issues - "
TempFileName = Filename & " " & Format(Now, "mmddyyyy")

    With ThisWorkbook
        .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
        .Close SaveChanges:=False
    End With
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM