Printing only specific pages.

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,040
Office Version
  1. 2019
Platform
  1. Windows
Hello Gurus,
How to print all pages in a series 1, 5, 9, 13, 17, 21... til last page.

I want the user to select
a. first page and
b. the series.

If the user selects 1 in option a , then begin printing from 1st page, and if the user selects 5 in the series, then print every 5th page. just like the series above.

The following is a macro that prints odd or even pages.

VBA Code:
Sub PrintOddEven()
    Dim TotalPages As Long
    Dim StartPage As Long
    Dim Page As Integer

    TotalPages = Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
    StartPage = InputBox("Enter starting page number")

    If StartPage > 0 Then
        For Page = StartPage To TotalPages Step 2
            ActiveSheet.PrintOut From:=Page, To:=Page, _
              Copies:=1, Collate:=True
        Next
    End If
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi, try this
VBA Code:
Sub printPages()
    Dim npage As String, n As Integer, pagA, pagB
    nPages = InputBox("Write first page and the series,separated by commas - es. 1,3")
    pagA = Split(nPages, ",")(0) + 0
    pagB = Split(nPages, ",")(1) + 0
    For n = pagA To Worksheets.Count Step pagB
        Worksheets(n).PrintOut
    Next
End Sub
 
Upvote 0
Hi, try this
VBA Code:
Sub printPages()
    Dim npage As String, n As Integer, pagA, pagB
    nPages = InputBox("Write first page and the series,separated by commas - es. 1,3")
    pagA = Split(nPages, ",")(0) + 0
    pagB = Split(nPages, ",")(1) + 0
    For n = pagA To Worksheets.Count Step pagB
        Worksheets(n).PrintOut
    Next
End Sub

Hello MrGes,

I am trying to print 5 pages just to see if it works. Your code will print all pages. In Input Box I put values = 1,3
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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