Export excel sheet as PDF to an existing folder

SSF1590

Board Regular
Joined
Oct 20, 2019
Messages
73
Hello,

I am looking for a code that allows to export an excel sheet as PDF that has name TARA-19-001 to an existing folder that was previously created with the same name in the following directory C:\Users\SSF1590\Desktop\TARA Project\Folders . The name of the file will change every time a new record is created(e.g. TARA-19-002, 003, 004, etc.). Therefore, the code should look for the folder name to save the pdf into that folder. Can I please have your help? I do not have an idea of how to do this.

Thank you.
 
Hello again. I just realized that I have a picture in my worksheet that is not being copy when I export along with the pdf file. Is it possible for the picture to be saved as well?
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi John. thank you for your feedback. I have 3 pictures in the sheet I export as pdf and neither of them saved in the pdf file. Do you have any idea what could be?

This is the code,

Dim File As Variant
Dim FileSpec As Variant
Dim Path2 As Variant
Dim Wks As Worksheet

Set Wks = ThisWorkbook.Worksheets("CARForm")
Sheets("CARForm").Visible = True

' // User input file name
File = TextBox1

' // Parent folder path
Path2 = "C:\Users\SS1590\Desktop\CAR Project\Folders"

' // Add final "" to the full file path if needed
FileSpec = IIf(Right(Path2, 1) <> "", Path2 & "" & File, Path2 & File)

' // If the folder does not exist then create it
If Dir(FileSpec, vbDirectory) = "" Then MkDir FileSpec

' // Save the worksheet as a PDF file
Wks.ExportAsFixedFormat xlTypePDF, FileSpec & "" & File & ".pdf"
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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