VBA save sheet as pdf with specified name in a specified folder

tdavis95

New Member
Joined
Feb 24, 2022
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hello.

So I am trying to create a macro that when the button on the sheet is pressed that specific sheet (not the whole workbook) will save as a pdf with the name "Initial Delivery Check dd-mm-yyyy hh-mm-ss"
I am not sure how to add the date and time to the name. I want the sheet to save as a new name each time so it does not override the previous copy. My current set up doesn't have date and time in the name so it just overwrites the previous version. I have looked through a lot of other examples and I can never get it to quite work for my set up.

My current VBA Code:

Sub CreatePDFSheet()
Sheet1.ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\INSERT COMPANY FOLDERS HERE\Forms\Completed Forms\Initial Delivery Check.pdf"
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try:
Sheet1.ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\INSERT COMPANY FOLDERS HERE\Forms\Completed Forms\Initial Delivery Check "& format(now(),"dd-mm-yy hh-mm-ss") &".pdf"
 
Upvote 0
Solution
Try:
Sheet1.ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\INSERT COMPANY FOLDERS HERE\Forms\Completed Forms\Initial Delivery Check "& format(now(),"dd-mm-yy hh-mm-ss") &".pdf"
Thank you so much, that worked. What a simple fix. I appreciate it.
 
Upvote 0
Something like the following:
Sheet1.ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\INSERT COMPANY FOLDERS HERE\Forms\Completed Forms\Initial Delivery Check "& Range("A1").value & format(now(),"dd-mm-yy hh-mm-ss") &".pdf"
 
Upvote 0
or if your cell contains the full filename then:
Sheet1.ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\INSERT COMPANY FOLDERS HERE\Forms\Completed Forms\"& Range("A1").value
 
Upvote 0
or if your cell contains the full filename then:
Sheet1.ExportAsFixedFormat xlTypePDF, Environ("Userprofile") & "\INSERT COMPANY FOLDERS HERE\Forms\Completed Forms\"& Range("A1").value
When I use either of them they "run" (no errors) but nothing saves to the file.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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