+ Reply to Thread
Results 1 to 3 of 3

VBA. How to loop on error, e.g. 01,02,03,04.....10,11,etc

  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    VBA. How to loop on error, e.g. 01,02,03,04.....10,11,etc

    Hi
    I have a code as below that first records the details of current active printer, then changes the active printer to a different network printer, and then switches back to a original printer.


    Please Login or Register  to view this content.
    I would need a bit of help with
    Please Login or Register  to view this content.
    namely how can I create a loop with Ne03 so it would loop from Ne01 to Ne16.
    E.g.
    if it errors with Ne01, then it tries Ne02, if it fails with Ne02 it then tries Ne03, etc, etc.
    So lets say the right answer is Ne15, and in this scenario it would have to loop through with Ne01 to Ne14 and on only proceed with the code with Ne15.


    Any ideas? As always I would appreciate any help. Cheers.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: VBA. How to loop on error, e.g. 01,02,03,04.....10,11,etc

    I don't think I've ever used the Application.ActivePrinter method, but I'm assuming it throws an error if you try to assign a printer which doesn't exist.

    If so then something like this might work:

    Please Login or Register  to view this content.
    Edited to add: If Excel doesn't throw an error until you try to open the printer dialog then move the "On Error GoTo 0" line to after the call to the printer dialog.
    Last edited by Andrew-R; 04-05-2012 at 04:43 AM.

  3. #3
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: VBA. How to loop on error, e.g. 01,02,03,04.....10,11,etc

    Thank you. This works brilliantly.
    Cheers

+ 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