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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
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.
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
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
Hi Sir,
I used above command in my code.
CreateObject("WScript.Network"). SetDefaultPrinter "Microsoft Print to PDF"
But it is not changing default printer from company printer to MS PRint to PDF here
How to do it otherwise now ?
The code to do what you actually want to do here is below. The issue you are running into is that the printer is not named properly.
You are ready to go. I've tested this on my own machine.
Note: If you kick off the pdf it will open up a Save File dialog. If you cancel out of that, it will return a 1004 error. The error handler routine will handle that cleanly and simply close the dialog. I've also included a couple of handy parameters (from, to) that you can include if those are helpful
Good luck. Code below
Sub Macro1()
On Error GoTo errorhandler
'MsgBox Application.ActivePrinter
'print statements
Application.ActivePrinter = "Microsoft Print to PDF on Ne01:"
ActiveWindow.ActiveSheet.PrintOut from:=1, to:=1, IgnorePrintAreas:=False
Application.ActivePrinter = "Canon MF650C Series UFR II on Ne03:"
'end print statements
errorhandler:
If Err.Number = 1004 Then
Exit Sub
Else
MsgBox "Error=" & Err.Number
End If
End Sub