【问题标题】:Reference a sub-folder of the inbox引用收件箱的子文件夹
【发布时间】:2020-06-21 08:45:37
【问题描述】:

我发现以下 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 位

【问题讨论】:

  • 在 64 位 Outlook 中运行它会发生什么?一般来说,香草 VBA 应该可以在 32/64 版本之间移植。
  • 有趣。我收到以下错误:“运行时错误'-2147221233 (8004010f)':尝试的操作失败。找不到对象。在调试器中它突出显示:Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Parent.Folders.Item("Batch Prints")。我已经验证了批量打印子文件夹和 Temp 文件夹一样存在。
  • “批量打印”是否与“收件箱”处于同一级别?您从收件箱开始,然后上至父 PST 文件,然后下至“批量打印”。这是正确的吗?
  • 可以使用 Parent 和 Folders 属性在层次结构中上下移动,但这并不总是很方便。在这个答案的最底部How to copy Outlook mail message into excel using VBA or Macros 是一个例程,它将返回对任何可访问 PST 文件中任何文件夹的引用。这可能更方便。几年前我为 Outlook 2003(32 位之前的版本?)编写了这个例程,它仍然适用于我当前的 64 位 Windows 10 笔记本电脑和 Outlook 365。
  • 谢谢托尼,仅这个问题就解决了我的问题。 “批量打印”是作为收件箱中的子文件夹创建的,而不是在收件箱之外。我将代码更改为Set Inbox = GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Folders("Batch Prints"),它现在可以正常工作了。谢谢!

标签: vba outlook


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    相关资源
    最近更新 更多