Print a PDF file with shell command in VBA

mrlionsss

New Member
Joined
Nov 11, 2020
Messages
10
Office Version
  1. 2007
Platform
  1. Windows
I am using this command in Excel VBA to print an existing PDF file as PDF

VBA Code:
Shell """" & "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" _
          & """/p /h """ & ActiveWorkbook.Path & "\" & Range("A8") & "invoice.pdf" & """"

This works great, however I would like to be able to overwrite the existing file. It obviously gives me an error message, that the file is being used, therefore I cannot overwrite it.

Is there a way to do this?

If not, is there a way to set a different predefined file name for the printed file? E.g. the file that needs to be printed is Range("A8") & "invoice.pdf" and the printed PDF would suggest Range("A8") & "invoice_printed.pdf"

Any help is appreciated!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try the following code:
Dim oShell As Object, oExec As Object
Set oShell = CreateObject("Wscript.Shell")
Set oExec = oShell.exec("""" & "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" _
& """/p /h """ & ActiveWorkbook.Path & "\" & Range("A8") & "invoice.pdf" & """")
DoEvents
oExec.Terminate
Set oExec = Nothing
Set oShell = Nothing

Regards,
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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