+ Reply to Thread
Results 1 to 32 of 32

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,258

    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,258

    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,258

    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,258

    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
    Forum Contributor
    Join Date
    06-09-2014
    MS-Off Ver
    Microst Office 365 Plus
    Posts
    143

    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,258

    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.

  16. #16
    Registered User
    Join Date
    04-30-2018
    Location
    Hungary
    MS-Off Ver
    2016
    Posts
    1

    Re: Printer selection problem due to Ne-port numbering

    Thank You very much, your code works perfect!

  17. #17
    Registered User
    Join Date
    08-10-2018
    Location
    Cambridge, England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Printer selection problem due to Ne-port numbering

    Excellent time-saving piece of code, thank you

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

    Re: Printer selection problem due to Ne-port numbering

    Hello David,

    Glad you liked the code. Which macro did you use?

  19. #19
    Registered User
    Join Date
    08-10-2018
    Location
    Cambridge, England
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Printer selection problem due to Ne-port numbering

    I copied the "Get Printer Names and Ports Module Code" (posted 08-06-2017) into a new module as suggested then ran the FindPrinterTest() macro.

    Thanks again

    David Buist

  20. #20
    Registered User
    Join Date
    03-05-2013
    Location
    uk
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Printer selection problem due to Ne-port numbering

    oh nice, thankyou for this

  21. #21
    Registered User
    Join Date
    04-09-2013
    Location
    UK
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2

    Re: Printer selection problem due to Ne-port numbering

    Oh my god, it's 2018 and your code has saved me. Thank you!!

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

    Re: Printer selection problem due to Ne-port numbering

    Hello yingcs,

    You're welcome. Which code did you use, post 8 or 13 ?

  23. #23
    Registered User
    Join Date
    04-09-2013
    Location
    UK
    MS-Off Ver
    2010, 2013, 2016
    Posts
    2

    Re: Printer selection problem due to Ne-port numbering

    Quote Originally Posted by Leith Ross View Post
    Hello yingcs,

    You're welcome. Which code did you use, post 8 or 13 ?
    Hell Leith,

    Actually I use your code in VB6!, an old legacy program that my company is still using.
    It works like a charm.

  24. #24
    Registered User
    Join Date
    11-12-2013
    Location
    US
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Printer selection problem due to Ne-port numbering

    Now it is 2019 and Thank You Leith! This stuff never gets too old. Used code from post #8 in Excel 2003 under XP. Works great!

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

    Re: Printer selection problem due to Ne-port numbering

    Hello djnicholsusa,

    Thank you for sharing which macro worked on your system. This will help others save time looking for the right solution.

  26. #26
    Registered User
    Join Date
    07-05-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Printer selection problem due to Ne-port numbering

    I used post #8 in excel 2007 with windows 10 and it works great. Thanks!

  27. #27
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 2000/3/7/10/13/16
    Posts
    49,996

    Re: Printer selection problem due to Ne-port numbering

    Quote Originally Posted by gtwedt View Post
    I used post #8 in excel 2007 with windows 10 and it works great. Thanks!
    Thanks for the feedback
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  28. #28
    Registered User
    Join Date
    01-20-2020
    Location
    Venice
    MS-Off Ver
    2003, 2010
    Posts
    1

    Re: Printer selection problem due to Ne-port numbering

    Thank you Leith Ross for both your code (#8 and #13).
    #13 gave me an error in my system, and I want to contribute to the community. I'm not an expert so I don't know what I'm writing, but it works!! And maybe it helps for compatibily problems when you use your code in old and new notebooks with old and new versions of Windows and Office. I'm using Office 2003 with Windows10 64 bit.
    Please Login or Register  to view this content.
    I eliminated PrtSafe and LongPtr => Long and :

    Please Login or Register  to view this content.
    This works for me, I hope also for others. Bye,

  29. #29
    Registered User
    Join Date
    10-26-2015
    Location
    Antwerp
    MS-Off Ver
    2010
    Posts
    3

    Re: Printer selection problem due to Ne-port numbering

    Thank you Leith Ross!

  30. #30
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 2016
    Posts
    4,882

    Re: Printer selection problem due to Ne-port numbering

    It seems to have been solved, but here is an alternative. If the printer name is consistent, you can call this function passing the printer name as a parameter, and it will return the full name of the printer including the "on NeXX"

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  31. #31
    Registered User
    Join Date
    09-19-2020
    Location
    Europe
    MS-Off Ver
    Office 2019
    Posts
    1

    Re: Printer selection problem due to Ne-port numbering

    How can i combine the altnernative from Arkadi with my code? I am struggling a bit how to understand and apply the aforementioned solutions.. :-(

    I am also struggling with the NeXX numbers which seems different on both workstations we use for the same Zebra printer. I've managed to look up the NeXX numbers and applied it into the macro but it doesn't work for the second workstation since the NeXX number is different

    Please Login or Register  to view this content.

  32. #32
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 2000/3/7/10/13/16
    Posts
    49,996

    Re: Printer selection problem due to Ne-port numbering

    Quote Originally Posted by Vieri View Post
    How can i combine the altnernative from Arkadi with my code? I am struggling a bit how to understand and apply the aforementioned solutions.. :-(

    I am also struggling with the NeXX numbers which seems different on both workstations we use for the same Zebra printer. I've managed to look up the NeXX numbers and applied it into the macro but it doesn't work for the second workstation since the NeXX number is different


    Administrative Note:

    Welcome to the forum.

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original.

    Please see Forum Rule #4 about hijacking and start a new thread for your query.

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread

+ Reply to Thread

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