Microsoft Print to PDF using VBA Code

Anonymous
2023-08-22T15:25:18+00:00

how to write VBA Code for Ensuring when print is done, it is done automatically using Microsoft Print to PDF using VBA Code in the macro called as "RUN PRINT"

Please share the code

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. Anonymous
    2023-08-26T18:28:07+00:00

    Hello

    Here is a VBA code to set the default printer to Microsoft Print to PDF:

    CreateObject("WScript.Network"). SetDefaultPrinter "Microsoft Print to PDF"

    Kind regards

    5 people found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. Anonymous
    2023-08-27T07:53:13+00:00

    Hello,

    If you run this macro, it will change the default printer to Microsoft Print to PDF, regardless of the current default printer.

    Kind Regards

    2 people found this answer helpful.
    0 comments No comments

14 additional answers

Sort by: Most helpful
  1. Anonymous
    2023-08-26T08:54:14+00:00

    Dear Sir,

    You are right but That excel sheet is going to be used by everyone and i can not set default printer for everyone in control panel. User are 1000 in numbers but they will use same excel file and same macro. So it is easy to force it using VBA Code here?

    How to set default printer using VBA code before sending print command ?

    0 comments No comments
  2. Anonymous
    2023-08-26T08:56:27+00:00

    Hello,

    You can use VBA code to set the default printer before sending a print command in Microsoft Office applications like Word, Excel, or Access. Here's how you can do it:

    Sub SetDefaultPrinterAndPrint()
        Dim defaultPrinter As String
        
    ' Store the current default printer
        defaultPrinter = Application.ActivePrinter
        
    ' Set the new default printer
        Application.ActivePrinter = "Printer Name Here"
        
    ' Your printing code here
        ' For example:
        ActiveSheet.PrintOut
        
    ' Restore the original default printer
        Application.ActivePrinter = defaultPrinter
    End Sub
    

    Replace "Printer Name Here" with the name of the printer you want to set as the default.

    Kind Regards

    0 comments No comments
  3. Anonymous
    2023-08-26T11:11:07+00:00

    Hi,

    your code is Ok but i want to set default printer always to Microsoft Print to PDF here.

    How to do it ?

    Regards,

    0 comments No comments