I am currently using a vba macro to fill in a pdf form and print it to another pdf. This works fine if the 'Microsoft Print to PDF' is the default printer however I do need to change this from time to time and forget to change it back. I am currently using this code below on another macro to change the default printer to an actual paper printer in the office; however, when I use this with the Microsoft Print to PDF printer it runs but does not change the default printer.
CreateObject("WScript.Network").SetDefaultPrinter "Microsoft Print to PDF"
You can set the active printer in excel vba as follows:
Application.ActivePrinter = "Brother HL-L2350DW series on Ne04:"
You can determine the printer name via Devices and Printers. However, the on Ne04: is a bit of a mistery. It is supposed to be the port but if you look in the printer properties and/or the registry this value is nowhere to be found.
I found the only way to determine this value is by setting a printer to default then enter Excel and enter ?ActivePrinter into the VBA Immediate window.
?ActivePrinter
Foxit Reader PDF Printer on Ne02:
Once you have the information you need it's easy to change your code as follows:
DefaultPtr =Application.ActivePrinter
Application.ActivePrinter = "Foxit Reader PDF Printer on Ne02:"
'***Do your printing here***
Application.ActivePrinter = DefalutPtr
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With