How to export different pages in separate pdf?

London12F

Board Regular
Joined
Jun 21, 2016
Messages
59
The VBA below can get the printout in one pdf:

Code:
Sub PrintInOnePdf()

Dim selectionRange As Range
Dim newRange As Range


PrintoutPath = "C:\Users\DK-01\Desktop\Scan\"


Set Sh = ActiveSheet
which = InputBox("Print which pages?")




NameOfFile = which 'before splitting "which"


which = Split(which, ",")
For i = LBound(which) To UBound(which)
    part = Split(which(i), "-")
    f = part(0)
    If UBound(part) = 0 Then
        t = f
    Else: t = part(1)
    End If
    
GoSub SetRange


Next i


selectionRange.Select


Selection.ExportAsFixedFormat _
        Type:=xlTypePDF, _
        Filename:=PrintoutPath & NameOfFile & ".pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=False


End


SetRange:


s = Range("print_area").Address()
P_Area = Split(s, ",")
p = Split(P_Area(0), ":")
    Set newRange = Range(Cells(55 * (f - 1) + 1, 2), Cells(55 * t, 13))
    
    
    If selectionRange Is Nothing Then
        Set selectionRange = newRange
    Else
        Set selectionRange = Application.Union(selectionRange, newRange)
    End If
Return


1000 End Sub



i.e. upon inputing the page numbers, say 1,3-5,
then pages 1, 3-5 will be exported as one pdf.

How to adjust the VBA so that the pdf will not merge,
and output as separate pdfs, i.e.
pdf file 1 with page 1;
pdf file 3 with page 3;
pdf file 4 with page 4;
pdf file 5 with page 5;
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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