Results 1 to 5 of 5

PRINT macro: prevent error when canceling at InputBox level

Threaded View

  1. #1
    Registered User
    Join Date
    10-01-2008
    Location
    sydney
    Posts
    16

    PRINT macro: prevent error when canceling at InputBox level

    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.
    Last edited by zusammen; 04-19-2009 at 07:51 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1