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!
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!