I'm using Excel 2010 and have Adobe Reader 11.
I'm trying to make a code in VBA that can print a specific PDF file. It's OK if the file opens first but it not necessary.
The file name change from time to time but it’s written in a specific cell in Excel. Let us say that it’s A1 in sheet1. The path is the same every time so that can be written directly in the code.
I have found this code on WWW but it doesn’t work for me.
- 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 = "J:\KAL\Machines\Extruder I\Køredata\Tegninger\"
- strFile = "370_Rev.pdf"
- printThis = PrintThisDoc(0, strDir & strFile)
- End Sub
I do hope that someone can help me.
Thank you in advance