Stuck while exporting worksheet to pdf ( with some complicated steps )

m93evans

New Member
Joined
Jul 8, 2018
Messages
3
Hi,

im having some issues exporting a worksheet to a PDF.

Where i want to use the following ranges in the filepath / filename of my new PDF

Dim Filename1 As String
Dim Filename2 As String
Dim Month As String
Dim Year As String


Filename1 = Range("A20")
Filename2 = Range("A7")
Month = Range("B20")
Year = Range("C20")

Dim Path As String
Path = "C:\Users\Myself\Desktop\Test01\Year\Month"

Currently i'm getting a runtime error in my save function, using:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
filename:="C:Path & Filename1 & Filename2 &.pdf"



I've tried lots of different ways to do this but nothing seems to be working.
any help welcome.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi & welcome to MrExcel
How about
Code:
filename:=Path & "\" & Filename1 & Filename2 & ".pdf"
 
Upvote 0
Thanks for that, Made the above amendment, nearly published pdf, then same run time error. "1004" document may be open, or an error may have been encountered while saving."
 
Upvote 0
Do all the folders exist?
Do your filenames contain any illegal characters?
Does a file with that name already exist?
 
Upvote 0
Got it, Had missed string manipulation in the filepath.
it now reads.

Dim Path As String
Path = "C:\Users\matt.evans\Desktop\BookingTest" & Year & "" & Month & ""

and now works.
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

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