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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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