Save as PDF in file location referenced in cell.

Tom Allen

Board Regular
Joined
Sep 26, 2014
Messages
92
Hi I'm a little stuck and would greatly appreciate any assistance. I have looked over similar threads regarding this topic but couldn't seem to find what I was looking for.

I currently have the following code that works great for saving as PDF with a file name referenced from certain cells.

Code:
Sub Create_PDF_Invoice()
Dim wsh As Worksheet, vWshs, vWshName

vWshs = Array("Standard Template")
With ActiveWorkbook
    For Each vWshName In vWshs
        .Worksheets(vWshName).ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
            "D:\Finance\Invoices Sent\" & "Invoice #" & .Worksheets(vWshName).Range("H5").Value & " - " & .Worksheets(vWshName).Range("H8").Value & " " & .Worksheets(vWshName).Range("A16").Value, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    Next vWshName
End With
End Sub

The above code saves as PDF in the location D:\Finance\Invoices Sent, it saves the PDF with a name in the following format for example Invoice #100 - CLIENTNAME Invoice Reference

I need to adapt it so that the folder is saves in is dynamic based on what is entered in cell H8. Cell H8 contains the client name and I have folders set up for each client where I would like to automatically save their invoices.

So for example it would save in D:\Finance\Invoices Sent\CLIENTNAME
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi Tom

Without testing this, and assuming the folder exists, I believe you need to change this part:
"D:\Finance\Invoices Sent\" & "Invoice #"

to this:
"D:\Finance\Invoices Sent\" & .Worksheets(vWshName).Range("H8").Value & "\Invoice #"

keep everything after that exactly as you had it before.

Andrew
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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