Export range to pdf with specific page breaks

cocobeans

New Member
Joined
Jul 8, 2020
Messages
10
Office Version
  1. 365
Platform
  1. MacOS
Hello,

I am attempting to create a sub that will select a range of cells ("A109:F263") and save as a pdf three pages long with a specific page break at above row 162 and above row 214 in the pdf document . In portrait.
Is this possible to do with vba ?
I am working on Mac if that makes a difference
Thanks
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try this:

VBA Code:
Option Explicit
Sub range_to_PDF()

Dim rng As Range

With ThisWorkbook.Worksheets("Sheet1")

Set rng = .Range("A109:F263")

.HPageBreaks.Add Before:=.Rows(162)

.HPageBreaks.Add Before:=.Rows(214)

rng.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
      "C:\temp\test_range", Quality:=xlQualityStandard, _
      IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

End With
End Sub
 
Upvote 0
Hello yky. I came up with a code that is exactly same as your s and it works . Thanks for your help.
 
Upvote 0

Forum statistics

Threads
1,215,313
Messages
6,124,201
Members
449,147
Latest member
sweetkt327

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