I have this VBA code that enables me to print PDF attachment using Outlook and it works fine
Code: Select all
'Reference : Tools >> Reference >> Adobe Acrobat 10.0 Type Library
Private 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
Sub PrintAttachmentsSelectedMsg()
Dim oMail As Outlook.MailItem
Dim obj As Object
Dim colAtts As Outlook.Attachments
Dim oAtt As Outlook.Attachment
Dim sFile As String
Dim sDirectory As String
Dim sFileType As String
For Each obj In ActiveExplorer.Selection
Set oMail = obj
'CHANGE TO SUIT
sDirectory = "D:\Attachments\"
Set colAtts = oMail.Attachments
If colAtts.Count Then
For Each oAtt In colAtts
sFileType = LCase$(Right$(oAtt.FileName, 4))
Select Case sFileType
Case ".pdf"
sFile = sDirectory & oAtt.FileName
oAtt.SaveAsFile sFile
AcrobatPrint sFile, "All"
End Select
Next oAtt
End If
Next obj
End Sub
Public Sub AcrobatPrint(FileName As String, PrintMode As String)
Dim AcroExchApp As Acrobat.CAcroApp
Dim AcroExchAVDoc As Acrobat.CAcroAVDoc
Dim AcroExchPDDoc As Acrobat.CAcroPDDoc
Dim num As Integer
Set AcroExchApp = CreateObject("AcroExch.App")
Set AcroExchAVDoc = CreateObject("AcroExch.AVDoc")
AcroExchAVDoc.Open FileName, ""
Set AcroExchPDDoc = AcroExchAVDoc.GetPDDoc
num = AcroExchPDDoc.GetNumPages - 1
If PrintMode = "All" Then
Call AcroExchAVDoc.PrintPages(0, num, 2, 1, 1)
Else
If num = 0 Then
Call AcroExchAVDoc.PrintPages(0, num, 2, 1, 1)
Else
Call AcroExchAVDoc.PrintPages(0, 1, 2, 1, 1)
End If
End If
AcroExchApp.Exit
AcroExchAVDoc.Close (True)
AcroExchPDDoc.Close
End Sub
Thanks advanced for help