+ Reply to Thread
Results 1 to 12 of 12

VBA for selecting printer

  1. #1
    Forum Contributor
    Join Date
    04-11-2014
    Location
    Norway
    MS-Off Ver
    Office 365 version 2302
    Posts
    152

    VBA for selecting printer

    Hi,

    I've searched and I've found others asking for the same, but I couldn't find any solution.

    I need a code to that automatically will print to PDFCreator even if this is not the default printer.

    The name of the printer is PDFCreator

    I used this code to find the printer on the server:
    Please Login or Register  to view this content.
    The result is PDFCreator on Ne00

    I can then print using this code:
    Please Login or Register  to view this content.
    The problem is that I want this to work on every computer on the network. Some will have the printer name PDFCreator on Ne01 or PDFCreator on Ne02 and so on.

    I need a code that will use PDFCreator on Ne0 and then search for the last number.
    Last edited by goranimo; 10-04-2016 at 07:42 AM.

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

    Re: VBA for selecting printer

    Have a look here http://www.excelforum.com/tips-and-t...excel-vba.html

  3. #3
    Forum Contributor
    Join Date
    07-23-2016
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    273

    Re: VBA for selecting printer

    You can use the GetPrinterFullNames code below to find a list of the printer names with ports in a string arrays then search the string for a printer containing the "PDFCreator" string. You can then set the active printer to be the printer name. NOTE that this code was originally from a fellow named By Chip Pearson and I only slightly modified it.

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    04-11-2014
    Location
    Norway
    MS-Off Ver
    Office 365 version 2302
    Posts
    152

    Re: VBA for selecting printer

    Kyle123:

    Thanks.

    I've copied and paste the Funvtion, but how can I get this to work?

    How will this code automatically select PDFCreator as printer, even when this is not the default printer?

    What do I need to change/add in my original code?
    Last edited by goranimo; 10-03-2016 at 03:30 AM.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA for selecting printer

    Try this.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Forum Contributor
    Join Date
    04-11-2014
    Location
    Norway
    MS-Off Ver
    Office 365 version 2302
    Posts
    152

    Re: VBA for selecting printer

    bakerman2: I tried your code but when i run the macro nothing happens.

    Can I test the function if Excel can find the port, using msgbox?
    Last edited by goranimo; 10-03-2016 at 06:45 AM.

  7. #7
    Forum Contributor
    Join Date
    04-11-2014
    Location
    Norway
    MS-Off Ver
    Office 365 version 2302
    Posts
    152

    Re: VBA for selecting printer

    Anyone?

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA for selecting printer

    If you put a stop point at the End Function row(put cursor in End function and press F9.
    Then start printer sub, in your Local Variables window you can see the value for GetPrinterPort2.

  9. #9
    Forum Contributor
    Join Date
    04-11-2014
    Location
    Norway
    MS-Off Ver
    Office 365 version 2302
    Posts
    152

    Re: VBA for selecting printer

    Now it works. I had blank document, that was the only reson that nothing happened

    Thank you everybody

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA for selecting printer

    You're welcome.

  11. #11
    Forum Contributor
    Join Date
    04-11-2014
    Location
    Norway
    MS-Off Ver
    Office 365 version 2302
    Posts
    152

    Re: VBA for selecting printer

    Just a bonus question

    Is there any way I can define a standard filename when printing to PDF?

    I already have a macro for saving with a spesific name, but I want to define PDF filename also.

    The code I have for saving is
    Please Login or Register  to view this content.

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: VBA for selecting printer

    Since this question isn't related to the current thread I suggest you start a new thread.
    Include the code you use to create your pdf-file and clearly explain the way you want to create the filename.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Selecting a printer
    By scott micklo in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-13-2016, 03:19 PM
  2. Page Break changes when selecting different printer
    By YOO629 in forum Excel General
    Replies: 2
    Last Post: 04-06-2015, 11:54 AM
  3. [SOLVED] Selecting printer according to filename
    By Thekratos in forum Excel Programming / VBA / Macros
    Replies: 36
    Last Post: 04-14-2014, 11:33 AM
  4. [SOLVED] Selecting a Printer from a Macro
    By EdWoods in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2013, 08:13 PM
  5. [SOLVED] selecting network printer
    By Bill Kuunders in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-28-2009, 06:06 AM
  6. selecting printer
    By Aaron in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2006, 06:30 PM
  7. Selecting a printer
    By Rob in forum Excel General
    Replies: 1
    Last Post: 06-29-2005, 09:05 AM

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