Adding a Specific Name to PDF Output VBA Code

alishan

New Member
Joined
Feb 6, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello Everyone,

I am leveraging a Macro to create PDF for my file. Currently, I am using following code to create PDF Output:

Sub Summary_PDF_Print()
'
' Summary_Print Macro
'

'
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\" & "ABC Royalties 2022_w_XYZ meter data & DEF meter data", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=5, _
OpenAfterPublish:=True

End Sub

This saves PDF name as "ABC Royalties 2022_w_XYZ meter data & DEF meter data". I want to have a PDF Output name as "ABC Royalties "Billing_Month"_w_XYZ meter data & DEF meter data"

where as Billing_Month is a Name I have defined in my excel and is referenced to a field. is it possible to do that ?

Thanks for your help in Advance.

Ali
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If "Billing_Month" is a named range with Workbook scope then:
VBA Code:
Sub Summary_PDF_Print()
'
' Summary_Print Macro
'

'
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\ABC Royalties " & Range("Billing_Month").Value & "_w_XYZ meter data & DEF meter data.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=5, _
OpenAfterPublish:=True

End Sub
 
Upvote 0
If "Billing_Month" is a named range with Workbook scope then:
VBA Code:
Sub Summary_PDF_Print()
'
' Summary_Print Macro
'

'
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ActiveWorkbook.Path & "\ABC Royalties " & Range("Billing_Month").Value & "_w_XYZ meter data & DEF meter data.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=False, _
IgnorePrintAreas:=False, _
From:=1, _
To:=5, _
OpenAfterPublish:=True

End Sub
Saved My Day.
Thank You!
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,255
Members
448,556
Latest member
peterhess2002

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