I'm using this code that I found in another thread. It opens a pdf file in Adobe Reader and prints it to a PDF. It works great, however, when I run the code, it triggers a dialog window in Adobe Acrobat, where you are suppose to enter the file name and hit save. I would need it to have the file name already set when printing and skip the part with the dialog window, in another way, is it possible, that all of this happens in the background?
Unfortunately, my vba knowledge doesn't go that far, so any help is appreciated!
Unfortunately, my vba knowledge doesn't go that far, so any help is appreciated!
VBA Code:
Option Explicit
Public Declare PtrSafe 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
Dim prtFile As String
strDir = "C:\Users\admin\Desktop\test"
strFile = "filetoprint.pdf"
printThis = PrintThisDoc(0, strDir & "\" & strFile)
End Sub