Forum Discussion
print a pdf in specific order
It appears that you are attempting to use the Adobe Acrobat Automation (AcroExch) to print specific pages of a PDF file. However, there are a couple of issues with your code:
- Creating AcroExch Objects: The code you have provided attempts to create objects for AcroExch, but it seems to be incomplete. Additionally, the AcroExch automation is not always straightforward, and it's essential to check for the correct version of Acrobat installed on your machine.
- Using Shell to Print PDF: An alternative approach is to use the Shell function to execute a command-line print operation. This is a more common method and is simpler to implement.
Here is an example using Shell to print specific pages of a PDF file:
The VBA code is untested. Please back up your file in advance.
Sub PrintPDFWithCustomOrder()
Dim pdfFilePath As String
pdfFilePath = "C:\Path\document.pdf"
' Specify the pages you want to print in a comma-separated string
Dim pdfPrintPages As String
pdfPrintPages = "2,1,10,4"
' Construct the print command
Dim printCommand As String
printCommand = "AcroRd32.exe /N /T """ & pdfFilePath & """ ""Microsoft Print to PDF"" /p " & pdfPrintPages
' Use Shell to execute the print command
Shell printCommand, vbHide
End Sub
In this example, the command AcroRd32.exe /N /T ... is used to print the specified pages of the PDF file to the "Microsoft Print to PDF" printer. The vbHide argument in the Shell function hides the Adobe Reader window during printing.
Make sure to adjust the paths, file names, and page numbers according to your specific requirements. Additionally, ensure that the Adobe Reader is installed on your machine.
The text and steps were edited with the help of AI. AI can make mistakes. Consider checking important information.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.