Add Page break in PDF Creation VBA

AddyBadd

New Member
Joined
Jan 31, 2023
Messages
1
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello

Could someone please advise how I can make a teo page pdf from my code:

Sub save_range_as_pdf()

Dim pdf_range As Range
Dim ws As Worksheet
Dim ID As String


Set ws = ThisWorkbook.Sheets("Pick")
Set pdf_range = ws.Range("B2:F50")

ID = Range("f2").Text
ID2 = Range("f5").Text

ws.PageSetup.CenterHorizontally = True
ws.PageSetup.CenterVertically = True

pdf_range.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="C:\PickNotes\" + ID + " " + ID2 + " (" + Format(Now(), "dd.mm.yy") + ") " + ".pdf", _
OpenAfterPublish:=True

End Sub

It works as is on my computer but when my colleague does it it cuts through an image when creating two pages. So I would like to add a page break in row 25.

Thanks

Addy
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
To create a two page PDF from your code, you can add a page break in row 25. To do so, add the following code to your existing code before the End Sub line:

ws.HPageBreaks.Add before:=ws.Range("B25")

The first line of this code adds a horizontal page break before row 25. This will ensure that the PDF will be split into two pages, with the first page ending at row 25.
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,307
Members
449,095
Latest member
Chestertim

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