+ Reply to Thread
Results 1 to 10 of 10

Macro to print to the default printer

  1. #1
    Registered User
    Join Date
    06-20-2012
    Location
    Northern Ireland
    MS-Off Ver
    2010
    Posts
    17

    Macro to print to the default printer

    Perhaps someone can help with with what is probably a very simple problem. I've been trawling through the internet to find a solution and all I ever seem to find is a solution for the inverse of my problem.

    So here it is...

    I have a macro on a Word document that will print the document via the macro (bypassing the print dialogue box). What I WANT to do it to print the document to the user's DEFAULT printer (not their current printer). In the majority of cases the default printer will be the current printer, but there are times when a user has another word document open and has the printer set to another printer (let's call it printer 2). The default printer is printer 1 but because they already have a Word doc open and have the printer 2 selected, when the new document (with the macro for printing) is used, the document prints to printer 2 and not printer 1 (even though printer 1 is the default printer - it's just that at this point in time it's not the current printer).

    Can anyone tell me what to put in the VBA script to make sure that when the document prints it prints to printer 1 (the default printer) every time, even if another Word doc is already open that has a different printer selected?

    Your help, as always, is greatly appreciated.

    Kind regards,

    Andre
    Last edited by Alves76; 04-22-2013 at 05:22 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: Macro to print to the default printer

    This will get you the default printer:
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-20-2012
    Location
    Northern Ireland
    MS-Off Ver
    2010
    Posts
    17

    Re: Macro to print to the default printer

    Thanks Kyle,

    One thing, that shows off how little I know...

    How do I link to that function in my own subroutine?

  4. #4
    Forum Contributor
    Join Date
    01-25-2013
    Location
    Chennai
    MS-Off Ver
    Excel 2003
    Posts
    112

    Re: Macro to print to the default printer

    Try this ??
    Please Login or Register  to view this content.
    HTH!!
    Safi.

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

    Re: Macro to print to the default printer

    It's used in your existing macro in place of the printer that you're currently printing out on, why not post your code so it makes it easier to help?

  6. #6
    Registered User
    Join Date
    06-20-2012
    Location
    Northern Ireland
    MS-Off Ver
    2010
    Posts
    17

    Re: Macro to print to the default printer

    Thanks Safi - If I've understood your code correctly the thing is that we have many different users globally so the printer name will be different for different users, otherwise it would be easier to set it to the one printer and then switch back, which is what I've seen online in other forums.

    I would like exactly what you wrote except the line that changes the printer would need to be the default printer as stated in the control panel. If there was a simple line of code for that I'd be done (I think).



    Kyle,

    Apologies I didn't think the code would have been relevant here. There's a bunch of code that does "stuff" (i.e. hides or unhides various sections of the document). Once that's done it simply comes to the print out part which I have as....

    Please Login or Register  to view this content.
    I don't want the print dialogue box to come up because I don't want people selecting more than 1 copy. If you want the other code I can paste it, but I don't want to put reams of code in unnecessarily.

    So, what you're saying is that I replace this line with what you added earlier in the thread?

    Thanks again Kyle and Safi.

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro to print to the default printer

    using Kyle's code I reckon it oughta be
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  8. #8
    Registered User
    Join Date
    06-20-2012
    Location
    Northern Ireland
    MS-Off Ver
    2010
    Posts
    17

    Re: Macro to print to the default printer

    Thank you Joseph.

    That worked.

    I always thought it would be a simple answer.

    Thanks again everyone

  9. #9
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Macro to print to the default printer

    no need to thank me-Kyle did all the hard work :-)

  10. #10
    Registered User
    Join Date
    06-20-2012
    Location
    Northern Ireland
    MS-Off Ver
    2010
    Posts
    17

    Re: Macro to print to the default printer

    True.

    The only thing is that when it gets to the last line the code seems to set the active printer as the default printer (although I don't see why). It's not much of a problem for me because I don't mind if the printer isn't set back to the active printer. The user can change that themselves - they use the default printer about 95% of the time anyway so it's not going to be an issue.

    When I was attempting this myself I was trying something similar except I was trying to write ActiveDocument.DefaultPrinter and it wasn't doing anything. I never thought to take away the ActiveDocument part.


    Thanks again.

+ 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