Printing only specific pages.

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,018
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

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

MrGes

New Member
Joined
Aug 9, 2019
Messages
12
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
 

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,018
Office Version
  1. 2019
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,129,499
Messages
5,636,684
Members
416,935
Latest member
Atulcp

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
Top