Create Macro to Save Active Sheet as PDF and save with in a Specific File Path

catyanne

New Member
Joined
Aug 16, 2018
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hi

I am trying to create a macro that picks up the file path that is entered on my Spreadsheet and save it as a PDF with in this File Path along with a specific file name:

The File Path is below - I need it to go to R1\R2\R3 (S:\Finance\F19\03 SEP 2018)

[TABLE="width: 250"]
<tbody>[TR]
[TD][/TD]
[TD]Q[/TD]
[TD]R[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]File Path[/TD]
[TD]S:\Finance[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]FY[/TD]
[TD]F19[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Month[/TD]
[TD]03 SEP 2018[/TD]
[/TR]
</tbody>[/TABLE]


I currently have a Macro to save as PDF below:

Code:
Sub SavePDF()
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("J1").Value & " " & Range("K1").Text _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False


End Sub


How do I incorporate the specific file path with in this macro.

Thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
where is it saving to when you run it? documents?
i think your need to change the directory
try add ChDir "S:\Finance\F19\03 SEP 2018" at the start

Code:
Sub SavePDF()

ChDir "S:\Finance\F19\03 SEP 2018"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("J1").Value & " " & Range("K1").Text _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False


End Sub

edit: using your cell references it should be

Code:
Sub SavePDF()

ChDir range("R1").value & "\" & range("R2").value & "\" and range("R3").value

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("J1").Value & " " & Range("K1").Text _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False


End Sub

hope that works
 
Last edited:
Upvote 0
Hi

Thanks for your reply. I can not add this as a directory. These cells are updated automatically based on the data within the spreadsheet (lookup tables based on dates and other info etc).

So I need it to pick up the data from those specific cells.

Thanks

where is it saving to when you run it? documents?
i think your need to change the directory
try add ChDir "S:\Finance\F19\03 SEP 2018" at the start

Code:
Sub SavePDF()

ChDir "S:\Finance\F19\03 SEP 2018"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Range("J1").Value & " " & Range("K1").Text _
    , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=False


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

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