VBA: Loop through pdfs and print

jaime1182

New Member
Joined
Dec 11, 2007
Messages
49
Office Version
  1. 2013
Platform
  1. Windows
Hi guys. Hope you are all well. I was hoping there is a solution to this dilemma I have.

I have a folder with 500+ pdfs, and I need to print a few pages from each.

Is it possible for a VBA to loop through all the pdfs in a folder (folder path to in cell A1), and print only certain pages (value in A2)?

Would it also be able to do a log on another worksheet listing filename in column A and any errors in column B (ie - page not found?)

Am currently doing this manually and am already struggling...
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I was able to find a code from John_W that worked somewhat. Was able to print the whole PDF on the printer (yay!)

VBA Code:
Option Explicit

Public Sub Print_All_PDF_Files_in_Folder()

    Dim folder As String
    Dim PDFfilename As String
   
    folder = "C:\temp\excel\"    'CHANGE AS REQUIRED
    If Right(folder, 1) <> "\" Then folder = folder & "\"
     
    PDFfilename = Dir(folder & "*.pdf", vbNormal)
    While Len(PDFfilename) <> 0
        Print_PDF folder & PDFfilename
        PDFfilename = Dir()  ' Get next matching file
    Wend

End Sub

Private Sub Print_PDF(sPDFfile As String)
    Shell "C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe /p /h " & Chr(34) & sPDFfile & Chr(34), vbNormalFocus
End Sub

Just wondering if there was a way to print only specific pages only?

Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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