+ Reply to Thread
Results 1 to 8 of 8

Changing the Printer in Excel VBA

  1. #1
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Changing the Printer in Excel VBA

    If you've tried to change the printer in Excel VBA, no doubt you've realised that it needs the printer port in order to work, this looks something like "NE01:". As this changes from computer to computer it can't be hard coded.

    Here's a solution that will get the printer port without looping over all possible versions until one works.

    Please Login or Register  to view this content.
    Below is an example for calling it:

    Please Login or Register  to view this content.
    Hope this helps someone
    Last edited by Kyle123; 11-04-2011 at 11:11 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing the Printer in Excel VBA

    Wouldn't this be sufficient ?

    Please Login or Register  to view this content.



  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Changing the Printer in Excel VBA

    Unfortunately no, it won't work for network printers as the slashes in the printer name will be appended to the registry key

    But if you can find a way to make it work, I'm all ears, much shorter
    Last edited by Kyle123; 11-04-2011 at 11:05 AM.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Changing the Printer in Excel VBA

    Maybe this will do (in analogy to SQL strings)

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Changing the Printer in Excel VBA

    Maybe and I'd love to try it but I've no network printers at home and I'm going to Mexico for 2 weeks tomorrow so I'm prying myself away from Excel for a bit I'll just have to wait in suspense

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Post Re: Changing the Printer in Excel VBA

    I don't think you have to.

    I found a simple solution using Word' VBA-library (although you dislike Word, I like it's VBA-library).
    It can be done simply

    Please Login or Register  to view this content.

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Changing the Printer in Excel VBA

    FWIW, I use:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Changing the Printer in Excel VBA

    Thanks both, they are good solutions. In terms of efficiency, my long code is the fastest, followed by rompers and then snb's. Though it's unlikely this will make much of a difference as generally the function is only called once.

    @snb, I don't dislike word, I just dislike the time it takes to open on my PC

    Thanks for your input

+ 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