PDA

View Full Version : Solved: Print PDF Range



dodonohoe
01-03-2013, 04:38 AM
Hi all,

I have the following code that opens a PDF document and prints the entire document. I was wondering if it's possible to print a named range such as pages 1-2 & 4-7?

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_HIDE As Long = 0&
Const SW_SHOW As Long = 5&

Sub PrintFile(strFilePath As String)
ShellExecute Application.hWnd, "Print", strFilePath, 0&, 0&, SW_HIDE
End Sub
Sub OpenFile(strFilePath As String)
ShellExecute Application.hWnd, "Open", strFilePath, 0&, 0&, SW_SHOW
End Sub

Sub PrintPDFsInputBox()

Dim Month As String
Dim sFile As String
Dim sFolder As String

Month = Application.Inputbox("Please enter the reporting month")

sFolder = "C:\"
sFile = Dir(sFolder & Month & "\saf*.pdf")
Do While sFile <> ""
PrintFile sFolder & sFile
sFile = Dir
Loop

End Sub

Many thanks,

Des

Kenneth Hobs
01-03-2013, 08:22 AM
I explained in your other thread that you would need Adobe Acrobat to do that.

If you don't have it, you could install a 3rd party program like pdfsam and split the pdf into one page per file and then print each page file that is needed using ShellExecute().

dodonohoe
01-04-2013, 03:26 AM
Thanks Kenneth. I will try that. The other solution you provided is working perfectly so thank you.

Des