Excel to PDF within the same directory

mallee

New Member
Joined
Apr 11, 2018
Messages
8
Hello again guys!

I'm either overthinking this, or not fully grasping the concept. I'm trying to save a file as PDF (with a file name from a cell value) to the same directory, but for whatever reason, it keeps saving the PDF's to one directory above.

Code:
  [FONT=Arial]s = Range("B2").Value[/FONT][FONT=Arial]
[/FONT]
[FONT=Arial]    ActiveSheet.<wbr>ExportAsFixedFormat Type:=xlTypePDF, Filename:= _[/FONT]
[FONT=Arial]        ThisWorkbook.Path & s, Quality:=xlQualityStandard, IncludeDocProperties _[/FONT]
[FONT=Arial]        :=True, IgnorePrintAreas:=False, OpenAfterPublish:=True[/FONT]

This way, if my Excel file is in C:\Users\PCName\Desktop\test\test2 folder, the PDF is being saved to C:\Users\PCName\Desktop\test instead.

So what am I missing? How do I force the PDF file to be saved in the same directory, in this case: C:\Users\PCName\Desktop\test\test2 :confused:
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
I should probably add that, if possible, I'm trying to avoid defining the string in the code itself, since the file will be moved around a lot between the different folders, I don't want to have to update the code with a new folder string each time I move the file.
 
Upvote 0
A bit hard without seeing all of the code, but make sure your Path is correct AND that it ends with a backslash.
Also, double check the value in B2
 
Upvote 0
hope this works
Code:
ChDir ActiveWorkbook.Path
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        s, Quality:=xlQualityStandard, IncludeDocProperties _
        :=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

EDIT:forgot s

Code:
s = Range("B2").Value
ChDir ActiveWorkbook.Path
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        s, Quality:=xlQualityStandard, IncludeDocProperties _
        :=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
 
Last edited:
Upvote 0
hope this works
Code:
ChDir ActiveWorkbook.Path
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        s, Quality:=xlQualityStandard, IncludeDocProperties _
        :=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

EDIT:forgot s

Code:
s = Range("B2").Value
ChDir ActiveWorkbook.Path
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        s, Quality:=xlQualityStandard, IncludeDocProperties _
        :=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
That fixed my issue. Wasn't aware of the ChDir before today. Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
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