从文件夹打印PDF正在打开Acrobat Reader,但未发送到打印机

问题描述 投票:2回答:1

我将Outlook中的一些VBA放在一起,以将PDF附件从Outlook文件夹发送到C:\ Temp \中的文件夹,然后将它们打印到默认打印机。

问题是,这是将Acrobat Reader打开到“最近”文件列表,而实际上没有将任何内容发送到默认打印机。

我当前的代码:

Option Explicit
Public Sub PrintAttachments()
Dim Inbox As MAPIFolder, Item As MailItem, Atmt As Attachment, FileName As String, i As Integer, Path As String

Set Inbox = Outlook.Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Batch Prints")

For Each Item In Inbox.Items
    For Each Atmt In Item.Attachments

    Path = "C:\Temp\Batch Prints\"
    If Len(Dir(Path, vbDirectory)) = 0 Then MkDir Path
        FileName = Path & Atmt.FileName
        Atmt.SaveAsFile FileName

        Call PrintPdf(FileName)

    Next
Next

Set Inbox = Nothing
End Sub

Public Sub PrintPdf(Filepath As String)
    Shell "C:\Program Files (x86)\Adobe\Acrobat Reader 2017\Reader\AcroRd32.exe /p /h " & Chr(34) & Filepath & Chr(34), vbHide
End Sub

没有错误发生,单步执行代码不会提示任何问题,但是Acrobat Reader应用程序将打开而不是打印。

enter image description here

是否确实缺少将这些文件实际发送到默认打印机的东西?

谢谢!

vba printing outlook adobe
1个回答
0
投票

尝试使用PDF的Specify privileged locations for trusted content设置

  1. 选择首选项>安全性(增强)
  2. 选择启用增强安全性选项
  3. 在“特权位置”部分中指定位置列表,以及然后单击确定

ShellExecuteA function MSDN


Option Explicit
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

Public Sub PrintAttachments()
    Dim Inbox As MAPIFolder
    Dim Item As MailItem
    Dim Atmt As Attachment
    Dim FileName As String
    Dim i As Integer
    Dim Path As String

    Set Inbox = Outlook.Application.GetNamespace( _
                            "MAPI").GetDefaultFolder( _
                               olFolderInbox).Folders("Batch Prints")

    For Each Item In Inbox.Items
        DoEvents
        For Each Atmt In Item.Attachments
        DoEvents

        Path = "C:\Temp\Batch Prints\"

        If Len(Dir(Path, vbDirectory)) = 0 Then MkDir Path
            FileName = Path & Atmt.FileName
            Atmt.SaveAsFile FileName

            ShellExecute 0, "print", FileName, vbNullString, vbNullString, 0

        Next
    Next

    Set Inbox = Nothing
End Sub

© www.soinside.com 2019 - 2024. All rights reserved.