Printing Multiple PDFs in a Folder

kambing007

New Member
Joined
Nov 2, 2016
Messages
2
Hi, I want to print all pdfs in a particular folder, and have a somewhat workable code:

Private Sub CommandButton1_Click()


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 (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe /p /h " & Chr(34) & sPDFfile & Chr(34), vbNormalFocus
End Sub


I am trying to change it to something like this:

Private Sub CommandButton1_Click()


Dim folder As String, nextFile As String, i As Long, LR As Long
Dim PDFfilename As String

folder = "C:\temp\excel"
LR = Cells(Rows.Count, "A").End(xlUp).Row

PDFfilename = Cells(i, "A")


For i = 1 To LR
Print_PDF folder & PDFfilename
Next i

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


But I keep getting a 1004 error on the particular line: PDFfilename = Cells(i, "A")

The reason I want to change the code is because while the 1st code is printing all pdfs, it is doing it out of order/not in sequence of the filename. I would have to rearrange the 100+ paper.

I am trying to change the code so that it prints based on a file list that I provide, listed in Cell A1 onwards.
The 2nd code works for when I am using it to rename all the pdfs, so I don't know where I'm doing wrong.

Please assist!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
OK I finally got it to work, but it so happens that it still skips a few files in column A to only come back and print them. Any idea guys?

I have a sample size of:

Test1.pdf
Test2.pdf
Test3.pdf
Test4.pdf
Test5.pdf


And it prints out:

Test1.pdf
Test3.pdf
Test2.pdf
Test5.pdf
Test4.pdf


The next time I try, I get a different sequence. I'm thinking maybe Reader is not coping with the print request so I added a
Application.Wait (Now + TimeValue("0:00:05"))
After Print_PDF

But still it seems random.

Any idea guys?
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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