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-22T15:29:04+00:00

    VBA code should force below option always while printing how to do it using VBA code ?

    0 comments No comments
  2. Anonymous
    2023-08-22T18:34:08+00:00

    Hey there, my name is Ajibola and I'm excited to help you out today!

    To automate printing to PDF using Microsoft Print to PDF in Excel using VBA, you can use the following code.

    Sub RUN_PRINT() ' Set the PDF printer as default printer Application.ActivePrinter = "Microsoft Print to PDF"

    ' Print the active sheet to PDF ActiveSheet.PrintOut

    ' Reset the default printer to the original printer Application.ActivePrinter = Application.DefaultPrinter End Sub

    If you have any further questions or need additional assistance, please feel free to ask. I'm here to help!

    If the reply was helpful, please don’t forget to upvote or accept it as an answer, Thank you

    Kind regards

    0 comments No comments
  3. Anonymous
    2023-08-24T12:02:42+00:00

    Hi,

    I am not able to print it to PDF using your code. Cn you please share another code to print it to PDF only.

    Please advice.

    0 comments No comments