Hi Guys,
I have a macro that asks the user what pages they would like to print on a particular sheet. In the example below, a button will be assigned to pages 1-5 on a sheet and thus the user has the option of printing from page 1 up to page 5. Any page number outside this range will result in an error message and the user will be asked to re-enter the end page number.
This is the code I pulled from this forum and partially modified:
Sub Print_Pages()
Dim StartPage As Long
Dim Endpage As Long
Dim Page As Integer
StartPage = 1
query: Endpage = InputBox("From page 1 to...?")
If Endpage <= 5 Then
For Page = StartPage To Endpage
ActiveSheet.PrintOut from:=Page, To:=Page, _
Copies:=1, Collate:=True
Next
Else
MsgBox "invalid number"
GoTo ask
End If
End Sub
Thing is if "cancel" is chosen on the input box at any stage, I get an error.
I'm a little confused about how or where to place an 'exit sub' statement?
Or is there a more succinct macro that allows the user to input the page numbers of their choice?
Any suggestions please?
Thanks Guys.
Z.
Bookmarks