Outlook VBA-查找附件是嵌入式的还是附件的

我正在编码一个小的VBA,该VBA在列表框中显示电子邮件的所有附件。 用户可以选择应从电子邮件中删除并存储在目标文件夹中的附件。 我还在电子邮件中添加了THML文件,其中包含所有已删除文件的列表(包括指向目标文件夹的每个文件的链接)。

我的图片有问题,因为它们可能是

  • 作为普通文件附加到电子邮件(与其他文件一样)
  • 嵌入电子邮件正文(如签名中的公司徽标)

我只想在列表框中显示那些作为文件附加到电子邮件的图像。 嵌入式邮件应被忽略。

以下是一些代码:

Sub SaveAttachment()

    Dim myAttachments           As Outlook.Attachments
    Dim olMailItem              As Outlook.MailItem
    Dim lngAttachmentCount      As Long
    Dim Attachment_Filename     As String

    Select Case True

        Case TypeOf Application.activeWindow Is Outlook.Inspector
            Set olMailItem = Application.activeInspector.currentitem
        Case Else

        With Application.activeExplorer.Selection
            If .Count Then Set olMailItem = .Item(1)
        End With

        If olMailItem Is Nothing Then Exit Sub

    End Select

    Set myAttachments = olMailItem.Attachments

    If myAttachments.Count > 0 Then

        For lngAttachmentCount = myAttachments.Count To 1 Step -1

            '-------------------------------------------------------------------------
            ' Add the attachment to the list of attachments (form)
            '-------------------------------------------------------------------------
            Attachment_Filename = myAttachments(lngAttachmentCount).FileName

            With UserForm1.lstAttachments

                .AddItem (Attachment_Filename)
                .List(lngAttachmentListPos,1) = Attachment_Type_Text
                .List(lngAttachmentListPos,2) = FormatSize(myAttachments(lngAttachmentCount).Size) & " KB"

            End With

        Next lngAttachmentCount

    End If

End Sub

我只添加了代码的相关部分,所以希望我不要忘记任何东西。

此刻,我显示所有附件(也包括嵌入式图像)。 当我能确定附件是否已嵌入时会很酷。

我在这里找到了可能的解决方案: Distinguish visible and invisible attachments with Outlook VBA 但是那里提供的源代码无法正常工作,似乎第2行和第3行中的两个URL不再存在。

我不是一个好的程序员,希望您能帮助我。 谢谢!

最诚挚的问候

OLLI

herichcq 回答:Outlook VBA-查找附件是嵌入式的还是附件的

我不确定这是否在所有情况下都有效,但是它是否可以在我的环境中使用。这意味着“正确测试”。

Const PR_ATTACH_CONTENT_ID = "http://schemas.microsoft.com/mapi/proptag/0x3712001F"

Function IsEmbedded(Att As Attachment) As Boolean
    Dim PropAccessor As PropertyAccessor
    Set PropAccessor = Att.PropertyAccessor
    IsEmbedded = (PropAccessor.GetProperty(PR_ATTACH_CONTENT_ID) <> "")
End Function

致电

If IsEmbedded(myAttachments(lngAttachmentCount)) Then
    ...
End If

看似神秘的url常量不是url,而是属性标识符。您可以在这里找到它们的列表:https://interoperability.blob.core.windows.net/files/MS-OXPROPS/%5bMS-OXPROPS%5d.pdf

该属性设置为附件的URL(如果嵌入)。如果未嵌入,则为空。

本文链接:https://www.f2er.com/3019609.html

大家都在问