VBA PrintOut to PDF

Pinaceous

Well-known Member
Joined
Jun 11, 2014
Messages
1,124
Office Version
  1. 365
Platform
  1. Windows
Good Day Everyone,

I'm working with a sub that accesses the PrintOut feature below but I'd like to see if I can use this PrintOut feature onto a PDF.

VBA Code:
Dim rngPrint As Range
Set rngPrint = Range("A1:S42")
rngPrint.PrintOut

Please let me know because I cannot figure it out.

Thank you!
pinaceous
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
VBA Code:
    Range("A1:S42").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\Range.pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
 
Upvote 0
VBA Code:
    Range("A1:S42").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\Range.pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Wow John_w!

That is fantastic!

How would you add "yyyymmdd\_hhmm" to the "Range.pdf" title?

Thank you!
pinaceous
 
Upvote 0
I'm not sure if the \ in "yyyymmdd\_hhmm" is a typo, because that character is a folder separator and can't be used in a file name.

VBA Code:
    Range("A1:S42").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\Range" & Format(Now, "yyyymmdd_hhmm") & ".pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
 
Upvote 0
I'm not sure if the \ in "yyyymmdd\_hhmm" is a typo, because that character is a folder separator and can't be used in a file name.

VBA Code:
    Range("A1:S42").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\Range" & Format(Now, "yyyymmdd_hhmm") & ".pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Wow thanks John_w!
 
Upvote 0
Hi John_w,

I am curious. How would I combine two of these subs together with different ranges?

For example, if I have the sub:

VBA Code:
Range("A246:S292").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\RANGE.pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

and

VBA Code:
Range("A293:S339").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\RANGE.pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

In using the first sub's Range("A246:S292") it produces a pdf with the page break ending at line 292. But when I combine them together such as in Range("A246:S2339") the page break ends at line 317.

So, my question is how do I combine both subs together in respecting their original page breaks onto one pdf?

Please let me know if you need my question clarified.

Thank you!
pinaceous
 
Upvote 0
VBA Code:
Range("A246:S292,A293:S339").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\RANGE.pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Should start the second range on a new page in the same PDF.
 
Upvote 1
VBA Code:
Range("A246:S292,A293:S339").ExportAsFixedFormat Type:=xlTypePDF, Filename:=ActiveWorkbook.Path & "\RANGE.pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
Should start the second range on a new page in the same PDF.
Hi John_w!

Yes, this worked and I appreciate your post!

R/
pinaceous
 
Upvote 0
Hey John_w!

I have a continued question on this thread, if you're interested. How do I make the Range take up the space of the pdf page? For example, currently when I chose a range it shrinks the information upon the pdf page(s).

Capture2.PNG



How would I provide the Range to take up the entire length (space) of that pdf page?

Curious, please let me know when you get a chance!


Respectfully,
pinaceous
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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