Export multiple ranges as PDF file

xsmurf

Board Regular
Joined
Feb 24, 2007
Messages
55
Office Version
  1. 365
Platform
  1. Windows
Hey,

I have a problem with exporting a range of data to an PDF file.
I looked around this website but none seems to give me the solution.

I am using this code to export a PDF file, which than will be attached to an email, this works perfect.
VBA Code:
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=strFileName, _
            OpenAfterPublish:=False

The range of cells it will pick is determent by the print range that has been set in excel, A1:I135
Within this range there a 2 page breakers, which will give me 3 pages.
Page 1 = A1:I54
Page 2 = A55:I108
Page 3 = A109:I135

The problem I have that when some of the data is hidden, because I don't need it, it will give me blank pages.
When Range 3 & 4 are hidden, the PDF will have a blank page in the middle.
When Range 1 & 2 & 6 are hidden, the PDF will have 3 pages but 2 are blank.
Range1 =A2:I27
Range2 = A28:I54
Range3 = A55:I81
Range4 = A82:I108
Range5 = A109:I135

Would it be possible to make a PDF file without the empty pages ?
So if Range 4 & 5 are hidden I will get only 2 pages.
If Range 3 & 4 are hidden I will get only 2 pages.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Try this:

VBA Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=strFileName, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, _
            OpenAfterPublish:=False
 
Upvote 0
Solution

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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