简体   繁体   中英

Excel Macro Save.As Date

I have a Macro that takes my Master workbook & saves a bunch of different copies with different labels.

Example of section for one workbook:

Range("E1:G1").Select
    ActiveCell.FormulaR1C1 = "099 Commercial"
    ChDir "T:\Accounting\Aspen Pre-Payroll (Shared)\_Payroll Emails"
    ActiveWindow.View = xlNormalView
    ActiveWindow.Zoom = 50
    ActiveWorkbook.SaveAs Filename:= _
        "T:\Accounting\Aspen Pre-Payroll (Shared)\_Payroll Emails\099 Payroll Bundle CREW & EXP.xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

So the label after the macro saves it looks like 099 Payroll Bundle CREW & EXP But I would like it to look like 099 Payroll Bundle 08-23-2016 CREW & EXP with the 08-23-2016 being the date located in the specific cell =RC[-1] However, the usuals " & Format(Date, "MM-DD-YYYY") & " & " & Format(Now(), "MM-DD-YYYY") & " will not work & gives me a compile error pop-up.

My knowledge about macros is limited so any help would be appreciated!

EDIT: ERROR it gives when I try to run macro

Try using Application.Text (replacing 'now()' with your date)

ActiveWorkbook.SaveAs Filename:= _
        "T:\Accounting\Aspen Pre-Payroll (Shared)\_Payroll Emails\099 Payroll Bundle" & Application.Text(Now(), "MM-DD-YYYY") & " CREW & EXP.xlsx" _
        , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

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