I need to print a pdf file from vba. I also need to set the print settings to 11x17.
I wanted to see if I could get the file to print using the code below. It didnt work. I mean, I dont get any error message, and if I use F8 to step through the routine, everything executes. But nothing happens.
I have lots of questions:
1. Is this a good method for what I'm trying to accomplish?
2. How can I parse print settings to the program?
-Could be handled with code like if filetype = .pdf, then send settings?
3. Why is nothing happening when I run testPrint?
I'm open to suggestions? About what I did wrong, or how to accomplish the pdf printing in general?
The excel file will be manipulated from multiple workstations and I have no control over setting references on other computers. Also, the location of the acrobat reader AcroRead32.exe file might not always be in the exact same location.
I was trying to use the shell32.dll method above, to avoid those problems. I figure I dont need to worry about references, or the AcroRead32.exe location if I let windows figure out the program association.
I wanted to see if I could get the file to print using the code below. It didnt work. I mean, I dont get any error message, and if I use F8 to step through the routine, everything executes. But nothing happens.
I have lots of questions:
1. Is this a good method for what I'm trying to accomplish?
2. How can I parse print settings to the program?
-Could be handled with code like if filetype = .pdf, then send settings?
3. Why is nothing happening when I run testPrint?
Code:
Option Explicit
Public 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
Public Function PrintThisDoc(formname As Long, FileName As String)
On Error Resume Next
Dim X As Long
X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function
Sub testPrint()
Dim printThis
Dim strDir As String
Dim strFile As String
strDir = "C:\Documents and Settings\ME\Desktop"
strFile = "myPDF.pdf"
printThis = PrintThisDoc(0, strDir & strFile)
End Sub
I'm open to suggestions? About what I did wrong, or how to accomplish the pdf printing in general?
The excel file will be manipulated from multiple workstations and I have no control over setting references on other computers. Also, the location of the acrobat reader AcroRead32.exe file might not always be in the exact same location.
I was trying to use the shell32.dll method above, to avoid those problems. I figure I dont need to worry about references, or the AcroRead32.exe location if I let windows figure out the program association.
Last edited: