Print to PDF - Save issue

CarlStephens

Board Regular
Joined
Sep 25, 2020
Messages
128
Office Version
  1. 2016
Platform
  1. Windows
Hello All,

I currently have the below print to pdf code, and cannot for the life of me work out where it is saving the file, which I believe it is doing as the message box comes up. Is there an option in the code to bring up "Save As" once the pdf has opened to chose the save location? Also, when the code is naming the file, I need to add the persons name which is in cell A3....what would I need to add to the code to attach the name in the file name? Thank you.

Sub PrintToPDF()
Dim invoiceRng As Range
Dim pdfile As String
'Setting range to be printed
Set invoiceRng = Range("C12:L50")
pdfile = "Seabourn Offer Letter" & " - " & Format(Now(), "DD-MMM-YYYY") & ".pdf"
pdfile = ThisWorkbook.Path & strfile
invoiceRng.ExportAsFixedFormat Type:=xlTypePDF, _
filename:=pdfile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
MsgBox "Offer letter created."
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
It's saving the file to the penultimate folder in the file path of the workbook containing code, with the final folder as the filename.
So if the workbook exists in R:\Folder1\Folder2\Folder3 the pdf will be saved in R:\Folder1\Folder2 and will be called Folder3.pdf.

Try it like
VBA Code:
pdfile = "Seabourn Offer Letter" & " - " & Format(Now(), "DD-MMM-YYYY") & ".pdf"
pdfile = ThisWorkbook.Path & "\" & pdfile
 
Upvote 0
It's saving the file to the penultimate folder in the file path of the workbook containing code, with the final folder as the filename.
So if the workbook exists in R:\Folder1\Folder2\Folder3 the pdf will be saved in R:\Folder1\Folder2 and will be called Folder3.pdf.

Try it like
VBA Code:
pdfile = "Seabourn Offer Letter" & " - " & Format(Now(), "DD-MMM-YYYY") & ".pdf"
pdfile = ThisWorkbook.Path & "\" & pdfile
Hello Sir,

The below code works a treat, however, I now need to save the created pdf to a folder location that is specified in cell H2. Would you be able to advise what I need to change the bold line to? Thank you so much.

Sub PrintToPDF()
Dim invoiceRng As Range
Dim pdfile As String
'Setting range to be printed
Set invoiceRng = Range("C7:L76")
pdfile = "Seabourn_Offer_Letter"
pdfile = ThisWorkbook.Path & "/" & pdfile
invoiceRng.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=pdfile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True

End Sub
 
Upvote 0
Change the ThisWorkbook to the sheet/cell where the full file path is located.
 
Upvote 0
No, it needs to be like
VBA Code:
Sheets("OL").Range("H2") & pdfile
 
Upvote 0
No, it needs to be like
VBA Code:
Sheets("OL").Range("H2") & pdfile
I get this error now and the pdf file is not open anywhere. Odd. I think I might need to restart my pc.

1637356192992.png
 
Upvote 0
What is the exact value in that cell?
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,107
Members
449,205
Latest member
ralemanygarcia

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