VBA code to print 2 external PDF files while working on excel sheet

Ramadan

New Member
Joined
Jan 20, 2024
Messages
16
Office Version
  1. 2021
Platform
  1. Windows
While working on excel worksheet I need to print 2 different external PDF files in the same folder for my clients to sign

here is the files paths "D:\Templates to Print\Acknowledgment.pdf" and "D:\Templates to Print\Works Permit.pdf"

can you please tel me what is the code that I can use to print such files
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I have found this code while searching through internet but unfortumately not working

VBA Code:
[sub print_file()
Print_and_Close_PDF "D:\Templates to Print\Acknowledgment.pdf"
End sub]
 
Upvote 0
I have found this code while searching through internet but unfortumately not working

VBA Code:
[sub print_file()
Print_and_Close_PDF "D:\Templates to Print\Acknowledgment.pdf"
End sub]
In that code, it looks like "Print_and_Close_PDF" would be a custom procedure or function that is created with VBA code.
Whereever you found that "code", you should dig a little deeper and see in the accompanying code for "Print_and_Close_PDF" is also contained in that posting (or in some Add-In they are using).
You will need to copy and paste that code in your VBA Project is order to call and use it.
 
Upvote 0
The following code works here on my two pdf files.
I've inserted the paths to your two files in this macro.

VBA Code:
Option Explicit

Sub PrintPDF()
Dim pdfPath As String
Dim pdfPath2 As String
Dim acroPath As String
Dim acroPath2 As String

' Set the path to the FIRST PDF file
pdfPath = "D:\Templates to Print\Acknowledgment.pdf"

' Set the path to Adobe Acrobat Reader (adjust if your path is different)
acroPath = "C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe"

' Print the PDF file
Shell """" & acroPath & """ /t """ & pdfPath & """", vbNormalFocus


' Set the path to the SECOND PDF file
pdfPath2 = "D:\Templates to Print\Works Permit.pdf"

' Print the PDF file
Shell """" & acroPath & """ /t """ & pdfPath2 & """", vbNormalFocus

End Sub

You must have Adobe Reader installed. Download here : PDF reader: The original PDF solution | Adobe Acrobat Reader
 
Upvote 0
Solution
I have found this code while searching through internet but unfortumately not working

VBA Code:
[sub print_file()
Print_and_Close_PDF "D:\Templates to Print\Acknowledgment.pdf"
End sub]

That appears to be my code from Excel VBA Open pdf (struggling). Follow all the instructions in that post.

But note that it relies on the default PDF application being able to print from the context menu when you right-click a PDF file in File Explorer.
 
Upvote 0

Forum statistics

Threads
1,225,195
Messages
6,183,485
Members
453,162
Latest member
Coldone

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top