Export multiple ranges as PDF file

xsmurf

New Member
Joined
Feb 24, 2007
Messages
31
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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
16,064
Office Version
  1. 2013
Platform
  1. Windows
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,191,516
Messages
5,987,017
Members
440,074
Latest member
Emmanuelian

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
Top