How to modify VBA so the order of print out follows input print pages?

London12F

Board Regular
Joined
Jun 21, 2016
Messages
59
The VBA can do the following:
1. Input print pages (e.g. 3,6,4)
2 .VBA can print out as pdf all input pages, but not in order (i.e. 6,3,4).

How to modify the VBA so that the print out is in order of input pages, i.e. 3,6,4?

Code:
Sub PrintSOR()

On Error GoTo 1000


ro = ActiveCell.Row
co = ActiveCell.Column


Dim selectionRange As Range
Dim newRange As Range


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


Set Sh = ActiveSheet
n = ActiveSheet.HPageBreaks.Count
    
which = InputBox("Print pages (1,3,5-" & n & ")?", PrintoutPath, "1-" & n)


NameOfFile = 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


Cells(ro, co).Select: End


SetRange:


s = Range("print_area").Address()
P_Area = Split(s, ",")
p = Split(P_Area(0), ":")


PL = Mid(p(0), 2, InStrRev(p(0), "$") - 2) ' left of printarea = B
PR = Mid(p(1), 2, InStrRev(p(0), "$") - 2) ' right of printarea
    
   Set newRange = Range(Cells(55 * (f - 1) + 1, Asc(PL) - 64), Cells(55 * t, Asc(PR) - 64))
    
    If selectionRange Is Nothing Then
        Set selectionRange = newRange
    Else
        Set selectionRange = Application.Union(selectionRange, newRange)
    End If
Return


1000 End Sub
 
Splitting it up by pages is a bit more involved but since you did not like either of my two methods, I did not see a reason to post code.

I bet you would be surprised how fast a copy and paste to a scatchworkbook would be. The only real issue is how to make each "page" into the ordered worksheets.

I guess you could print to a pdf printer? Since you are asking for input anyway, the macro could be very simple to maybe pre-fill the print dialog and then show it.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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