How to add/append date to a converted pdf

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
564
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Is there a way to add/append a time date stamp after the PDF name followed by ".pdf" without any runtime errors occuring?
Ex:
CravingFish_7/21/2020_14:11:23.pdf

VBA Code:
Private Sub btnSave_Email_Click()
    Dim sPath As String
    Dim sFilename As String
    
    sPath = "C:\Users\NameHere\Desktop\Saved PDF TEST\"
    sFilename = ThisWorkbook.Name
    ActiveSheet.ExportAsFixedFormat xlTypePDF, sPath & sFilename

End Sub

Thank You
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Not with the / or : as they are illegal characters in a filename, if you use a legal character then yes i.e. something like...
VBA Code:
    sFilename = ThisWorkbook.Name & "_" & Format(Now, "mm-dd-yyyy_hh mm") & ".pdf"
    ActiveSheet.ExportAsFixedFormat xlTypePDF, sPath & sFilename

Illegal characters in Windows are...

< (less than)
> (greater than)
: (colon)
"" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)

there are some other rules but too much (and irrelevant to the post) to go into here.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,790
Messages
6,126,923
Members
449,348
Latest member
Rdeane

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