vba code: save each hpagebreak as pdf with cell.value filename

shoaibasghar_s

New Member
Joined
Jul 28, 2015
Messages
8
i have a sheet with horizontal pagebreaks set correctly, i want to save each pagebreak as separate pdf file, and name of file be the text in first cell on each page. i know how to save page as pdf, i need to know how to print at each horizontal pagebreak, and how to select first cell after each hpagebreak.

thnx
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
ok so i have managed it on my own but with one minor problem

my code is
Code:
Sub pdf_level_transmitter()
Dim HPB As HPageBreak
Dim RW As Long
Dim rr As Range
If ActiveSheet.HPageBreaks.Count = 0 Then
MsgBox "There are no HPageBreaks"
Exit Sub
End If

With Application
.ScreenUpdating = False
.EnableEvents = False
End With
RW = 2
For Each HPB In ActiveSheet.HPageBreaks
If HPB.Type = xlPageBreakManual Then

strDir = "C:\Users\SA\Desktop\" & ActiveSheet.Name
ChDir strDir
filesavename = "3-" & ActiveSheet.Rows(RW).Columns(19).Value
Set rr = Range(ActiveSheet.Rows(RW).Columns(2), ActiveSheet.Rows(HPB.Location.Row - 1).Columns(42))
rr.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filesavename, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False

End If
RW = HPB.Location.Row
Next


End Sub
problem with this code is that it does not save last page, so i had to add an extra pagebreak. how can i eliminate this..?
 
Upvote 0

Forum statistics

Threads
1,215,143
Messages
6,123,285
Members
449,094
Latest member
GoToLeep

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