Need a macro that will save a file that has the today's date in the filename.

agc3278

New Member
Joined
Nov 14, 2007
Messages
15
I have a macro which saves a file as a pdf., but would like to adjust it to include the current date in the filename. The code is below.

Sub SaveAsAuto()
Application.ScreenUpdating = False
Sheets("Primary Bank").Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"R:\" & Range("M69") & "Branch NNN Proofsheet MMDDYY", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Sheets(Array("Primary Bank", "Secondary Bank")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"R:\" & Sheets("Primary Bank").Range("M69") & "Branch NNN Proofsheet MMDDYY", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Sheets("Primary Bank").Select
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try:
& "Branch NNN Proofsheet " & Date,

You can add Format (Date, "MMDDYYYY") if you wish
 
Upvote 0
Hi Steve,

Thank you for the reply. I am having trouble entering the code to format correctly or the just adding the date in general. I keep getting the 400 run error. Any thoughts?

Thanks again!
 
Upvote 0
This line should be:

Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "R:\" & Range("M69") & "Branch NNN Proofsheet " & Format(Date, "MMDDYY") & ".pdf", Quality:= _
        xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
        OpenAfterPublish:=False

Whats in M69? Does it have a slash at the end? Or you may need & "\Branch NNN.......
 
Upvote 0
Thank you so much Steve!! It worked exactly how I needed it to!!! There is nothing in M69. M69 is just the end of the range that i wanted saved. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,400
Messages
6,119,284
Members
448,885
Latest member
LokiSonic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top