+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 25

Printer selection problem due to Ne-port numbering

  1. #1
    Registered User
    Join Date
    01-19-2004
    Posts
    8

    Printer selection problem due to Ne-port numbering

    Hello,

    I have a macro which sents data to a printer. The printer has a certain 'Ne' port number. The problem is that this number (i.e. 'Ne03') sometimes changes . When that happens, the macro halts.

    How can I bypass this problem?

    Application.ActivePrinter = "HP Officejet J6400 series op Ne02:"



    Many thanks in advance,


    Jim van Zuijlen

    The Netherlands

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,009

    Re: Printer selection problem due to Ne-port numbering

    Hello jimfx,

    My question to you is why is the printer changing? Is the code being run on different machines? If it is being run on different machines, why not use the default printer?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    01-19-2004
    Posts
    8

    Re: Printer selection problem due to Ne-port numbering

    I don't know. It sometimes happens when a USB device is being connected to the PC, it than can happen that the Ne-port numbers changes on devices / printers.

  4. #4
    Registered User
    Join Date
    01-19-2004
    Posts
    8

    Re: Printer selection problem due to Ne-port numbering

    The macro prints also to a PDF printer, so muliple printer-ports are being used in the code.

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,009

    Re: Printer selection problem due to Ne-port numbering

    Hello jimfx,

    Would it work for you to let the user select the printer?

  6. #6
    Registered User
    Join Date
    01-19-2004
    Posts
    8

    Re: Printer selection problem due to Ne-port numbering

    Hi Leith,
    You mean Application.Dialogs(xlDialogPrint).Show
    will the macro wait until user makes selection?

    but the macro is used a lot, better would be automatic selection.

    Rgts,
    Jim

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,009

    Re: Printer selection problem due to Ne-port numbering

    Hello jimfx,

    If you want the macro to select a printer automatically then use the default printer. What are you printing out?

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,009

    Re: Printer selection problem due to Ne-port numbering

    Hello jimfx,

    This macro works with Excel 2003 or any Windows system using NTFS. It looks for a printer with name you suppply and returns the printer and the port. If the printer can not be found then an empty string is returned.
    Please Login or Register  to view this content.
    [b]Example[b/]
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    08-17-2013
    Location
    Hoekwil, South Africa
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Printer selection problem due to Ne-port numbering

    Thanks for the great piece of Code. Worked like a dream

  10. #10
    Registered User
    Join Date
    06-04-2015
    Location
    Dublin, IRELAND
    MS-Off Ver
    2007
    Posts
    1

    Re: Printer selection problem due to Ne-port numbering

    Excellent, exactly what I needed.

  11. #11
    Registered User
    Join Date
    04-24-2017
    Location
    GŁtersloh, GERMANY
    MS-Off Ver
    2010
    Posts
    1

    Re: Printer selection problem due to Ne-port numbering

    Even 8 years later it has helped a lot. Thank you

  12. #12
    Registered User
    Join Date
    06-09-2014
    Posts
    70

    Re: Printer selection problem due to Ne-port numbering

    This code has been a lifesaver and has worked perfectly... until today. It seems Microsoft have released an update that causes it to break on the line Set RegObj = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv"). Now when I run it, I get the following error:

    Please Login or Register  to view this content.
    This is on Excel 2016.

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,009

    Re: Printer selection problem due to Ne-port numbering

    Hello MoldyBread,

    After researching this error, I found nothing useful. As an alternate to the WMI code, I wrote this API code to the same thing. It actually is a bit better since it will return all printer names that partially match the printer name you provide.

    This code works on Windows 7 and up with either 32 or 64 bit Office. Add a new VBA Module to your project and paste this code into it.

    Get Printer Names and Ports Module Code
    Please Login or Register  to view this content.
    Example - List all HP Printers
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 08-06-2017 at 07:27 PM.

  14. #14
    Registered User
    Join Date
    08-11-2017
    Location
    Osaka, Japan
    MS-Off Ver
    2016
    Posts
    1

    Re: Printer selection problem due to Ne-port numbering

    I also came across this problem in a different macro that uses the same command to enumerate the registry.

    After a bit of trial and error testing I have worked out that the recent update KB4011051 is what caused this odd error to appear. Uninstalling KB4011051 fixes the problem, but of course whatever issues fixed by the update will then be unfixed. For now I have chosen to uninstall the update as I don't have time to rewrite my macros.
    Last edited by trunder; 08-11-2017 at 01:35 PM. Reason: Grammatical error.

  15. #15
    Registered User
    Join Date
    11-27-2017
    Location
    UK
    MS-Off Ver
    Office 2016
    Posts
    1

    Re: Printer selection problem due to Ne-port numbering

    Thank you - this was a brilliantly timesaving snippet.

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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