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
Hey,
VBA code snippet that you can use to print an Excel worksheet to a PDF file. Make sure you adjust the code according to your specific needs:
vbaCopy code Sub PrintToPDF() Dim ws As Worksheet Dim pdfPath As String ' Set the worksheet you want to print Set ws = ThisWorkbook.Sheets("Sheet1") ' Replace "Sheet1" with your sheet's name ' Set the PDF file path and name pdfPath = "C:\Path\To\Your\File.pdf" ' Replace with your desired file path ' Print the worksheet to PDF ws. ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPath, Quality:=xlQualityStandard End Sub Instructions for using the code: 1. Open the Excel workbook you want to work with. 2. Press Alt + F11 to open the Visual Basic for Applications (VBA) editor. 3. Click Insert > Module to insert a new module. 4. Copy and paste the provided code into the module. 5. Modify the code: • Set the ws variable to the worksheet you want to print. • Set the pdfPath variable to the desired file path and name for the PDF. 6. Close the VBA editor. 7. Press Alt + F8 to open the "Macro" dialog box. Select "PrintToPDF" (or whatever you named your macro) from the list and click "Run."
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
Hi,
I have workbook and not worksheet here.
How to write that code?
I have a workbook with 3 worksheets, So I have PRINT button which prints all these 3 sheets here.
How to write the code for that ?
PRoblem is when i am runnignthe code, it is printing it with Company printer and not MS PRint to PDF here
Hello,
To print all the worksheets in a workbook, you can use the following VBA code:
Sub PrintAllSheets() Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets ws. PrintOut Next ws End Sub
This code will print all the worksheets in the active workbook. If you want to print only specific worksheets, you can modify the code accordingly. Regarding your issue with printing to PDF, you can try changing the default printer to Microsoft Print to PDF before running the code. To do this, follow these steps:
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