引用收件箱的子文件夹

时间:2016-08-25 09:57:16

标签: vba outlook-vba

我发现以下Outlook VBA脚本批量打印子文件夹中的所有电子邮件附件:

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

Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item("Batch Prints")

For Each Item In Inbox.Items
    For Each Atmt In Item.Attachments
        ' all attachments are first saved in the temp folder C:\Temp.  Be sure to create this folder.
        FileName = "C:\Temp\" & Atmt.FileName
        Atmt.SaveAsFile FileName
        ' please change the program folder accordingly if the Acrobat Reader is not installed on drive C:
        Shell """C:\Program Files\Adobe\Reader 8.0\Reader\acrord32.exe"" /h /p """ + FileName + """", vbHide
    Next

    Item.Delete  'remove this line if you don't want the email to be deleted automatically
Next

Set Inbox = Nothing
End Sub

来源:http://www.howtogeek.com/howto/microsoft-office/batch-print-pdf-attachments-in-outlook/

我的问题是:是否可以将此脚本转换为64位,因为安装32位Office不是一种选择。

我找到了PtrSafe,但在.dll声明方面似乎只是相关。

Office版:2016 64位

1 个答案:

答案 0 :(得分:0)

如果您的文件夹是子文件夹,那么您将代码设置为

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

如果它是多个子文件夹,那么

Folders.("Folder name").Folders.("Batch Prints")

要在64位Outlook中使用宏,您需要将PtrSafe添加到声明:

Compatibility Between the 32-bit and 64-bit Versions of Office 2010