Macro to save sheet as PDF with unique name

Tom Allen

Board Regular
Joined
Sep 26, 2014
Messages
92
Hi I am using the following macro code to save a sheet as a PDF. However the name of the saved PDF comes out as the the worksheet name which is called Standard Template.

I was wondering if anyone knew how to edit the code so that the name comes out as the following: Invoice #(value of cell H5)

Cell H5 contains a unique invoice number so for example if cell H5 had the number 10 in it then the PDF would save as Invoice #10

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\" & vWshName, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    Next vWshName
End With
End Sub

Any help would be appreciated.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Try

Rich (BB 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\" & vWshName.Range("H5").Value, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    Next vWshName
End With
End Sub
 
Upvote 0
Thanks for the reply. Unfortunately the code seems to return Run-time error '424' Object required
 
Upvote 0
Thank you that worked. Sorry I'm a bit of a novice at this but how would I edit the code again so that the name comes out as: Invoice #(value of H5)
Currently the name comes out as the value of H5 but it would be perfect if I could add a small bit of text before that value so the entire name would be something like Invoice #10 instead of just 10
 
Upvote 0

Forum statistics

Threads
1,213,567
Messages
6,114,342
Members
448,570
Latest member
rik81h

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