VBA routine: save a file as PDF and add a specific date

Burrgogi

Active Member
Joined
Nov 3, 2005
Messages
340
Office Version
  1. 2010
Platform
  1. Windows
Every week, I send out a schedule to various people. Some of the people have complained that they don't have Excel installed on their home computers so I've started sending out the schedule in PDF format. Problem easily solved. However, I'd like to add a specific date to the filename itself. I usually edit the schedule on Sat or Sun and email it to everyone. Cell A5 contains the first day of the schedule in mm-dd-yy format.

I'd like the filename to be: "Schedule for mm-dd-yy.xlsx"

I searched the forums and this thread is actually a very close fit to what I need. However, when I run it - I get a 400 error. Any help would be greatly appreciated.

P.S. And yes... i did change the C5 to A5 in VBA routine. I still get the error.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Ooops, I meant to say that the filename should read as:

"Schedule for mm-dd-yy.pdf" (not xlsx)
 
Upvote 0
How about:
VBA Code:
Sub SavePDF()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\Schedule for " & Format(Range("A5").Value, "mm-dd-yy") & ".pdf", _
        Quality:=xlQualityMinimum, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
 
Upvote 0
Awesome! Thank you John_w. Just for my own sake of knowledge, do you know why I was getting a 400 error on that first routine I found?
 
Upvote 0
Maybe because the path "C:\Users\Test\Desktop\" doesn't exist.

Or, without an explicit VBA Format (as in my code), the variable 'x' date string is formatted as the default system date format which may contain characters (e.g. forward slash) which are invalid in file names.
 
Upvote 0
Maybe because the path "C:\Users\Test\Desktop\" doesn't exist.

Or, without an explicit VBA Format (as in my code), the variable 'x' date string is formatted as the default system date format which may contain characters (e.g. forward slash) which are invalid in file names.

Makes total sense. Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

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