+ Reply to Thread
Results 1 to 5 of 5

PRINT macro: prevent error when canceling at InputBox level

  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:

    Please Login or Register  to view this content.
    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.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: PRINT macro: prevent error when canceling at InputBox level

    It's because the Inputbox returns "" when Cancel or escape is used.

    Change the variable type and check for that return value

    Please Login or Register  to view this content.
    You should also check for non numeric values.
    Or use the Application.Input box which would allow you to restrict input to numbers
    Cheers
    Andy
    www.andypope.info

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

    Re: PRINT macro: prevent error when canceling at InputBox level

    Hi,

    Thanks Andy. For the benefit of others, my final code is as follows:

    Please Login or Register  to view this content.
    Can you confirm that this isn't overly 'sloppy' in terms of coding? As a newbie I feel as though I could run into problems down the track if my code is scratchy.
    Last edited by zusammen; 04-19-2009 at 07:51 AM. Reason: question best left for a new thread

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: PRINT macro: prevent error when canceling at InputBox level

    The code is okay. Any changes would only be style/personal preference changes rather than to correct sloppy code

    For restricting numeric entry in cells see Data Validation

    For restricting numeric entry in input box see the Type argument for Application.Inputbox

    If you need further help on either then start a new thread.

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

    Re: PRINT macro: prevent error when canceling at InputBox level

    A grateful thank-you for your help!

    Cheers,

    Z.

+ Reply to Thread

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