【问题标题】:Outlook: handling Property Accessor hidden attachment errorOutlook:处理属性访问器隐藏附件错误
【发布时间】:2019-08-20 08:48:57
【问题描述】:

我有一个脚本可以检查所有发送到共享邮箱的邮件。它检查附件类型并忽略检查中的隐藏附件(如邮件中的图像)。它在我的计算机上完美运行,但是当我将它安装在用户计算机上时,有时会出现此错误:

Run-time error '-2147221233 (8004010f)':
The property "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B" is unknown or cannot be found.

我已经在网上搜索并找到了原因 - 某些附件没有隐藏附件的属性(可能)。但是如何处理这个问题呢?我试图制作一个错误处理程序,但它使脚本无法正常工作。该脚本的主要思想是仅接受带有 PDF 附件的邮件,并且使用当前的错误处理程序有时会接受包含其他附件类型的邮件。

这是检查附件的代码部分:

Private Sub objItems_ItemAdd(ByVal Item As Object)
Const PR_ATTACHMENT_HIDDEN As String = "http://schemas.microsoft.com/mapi/proptag/0x7FFE000B"

Dim myAtt As Outlook.Attachment
Dim allPdf As Boolean
Dim hidNum As Integer

allPdf = True
hidNum = 0

Dim pa As PropertyAccessor

Dim objWatchFolder As Outlook.Folder
Set objNS = Application.GetNamespace("MAPI")

Dim Recip As Outlook.Recipient
Set Recip = objNS.CreateRecipient("test@mail.com")

Set objWatchFolder = objNS.GetSharedDefaultFolder(Recip, olFolderInbox)


For Each myAtt In Item.Attachments
        Debug.Print myAtt.DisplayName
        Set pa = myAtt.PropertyAccessor

        On Error GoTo Handler

        If Not pa.GetProperty(PR_ATTACHMENT_HIDDEN) Then
            If Right(LCase(myAtt.FileName), 4) <> ".pdf" Then
                allPdf = False
            End If
        Else
            hidNum = hidNum + 1
        End If
NextAtt:
    Next myAtt

If allPdf = False Or Item.Attachments.Count = hidNum Then
    Item.Move objWatchFolder.Parent.Folders("Error")
End If


Set Item = Nothing
Set myAtt = Nothing
Set pa = Nothing
Set objWatchFolder = Nothing
Set Recip = Nothing

Exit Sub

Handler:
Resume NextAtt

End Sub

我想问题是在出错后它只是忽略了导致错误的附件并转到下一个。我还能在错误处理程序中检查附件的附件类型吗?

如果隐藏附件没有隐藏附件属性怎么办?这甚至可能吗?除非有任何其他方法可以将隐藏的附件与其他附件区分开来,否则它将使 sript 无用。

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    是的,异常是设计使然,您需要处理它。这在 VBA 中当然很混乱。

    使用on error resume next / Err.Clear / Err.Number / Err.Description - 见https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/err-object

    【讨论】:

    • 我不确定如何在我的情况下使用它。我做了类似 On Error GoTo Handler, Handler: If Err.Number 0 Then If Right(LCase(myAtt.FileName), 4) ".pdf" Then allPdf = False End If End If End If Resume NextAtt
    • 尝试“On Error Resume Next”/“Err.Clear”/调用 PropertyAccessor/检查 Err.Number
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多