【问题标题】:Displaying mailitem generates Runtime Error -2147467259显示 mailitem 生成运行时错误 -2147467259
【发布时间】:2018-06-21 03:09:30
【问题描述】:

如果 conversationID 与请求相同,我会遍历 MailItem 集合以显示 MailItem。

但是,似乎,当搜索的项目不在 ActiveSelection 上并且调用 MailItem.Display 函数时,它会产生“运行时错误 -2147467259”

Outlook 无法执行此操作,因为打开了一个对话框。请关闭并重试。

这里是代码

'  email_link_Click()                                                                   '
'           -> Compares the ConversationID sent through to get the email                '
Sub email_link_Click()
    Dim searchFolder As Object

    Set olNs = Application.GetNamespace("MAPI")
    Set olFldr = olNs.GetDefaultFolder(olFolderInbox)
    Set searchFolder = olFldr

    If Not Me.email_folder.Caption = "Inbox" Then
       Set searchFolder = olFldr.Folders(Me.email_folder.Caption)
    End If

    searchFolder.Items.Sort "[Subject]", False

    For Each emailvar In searchFolder.Items
        If emailvar.ConversationID = Me.conversationID_label.Caption Then
            FilingPrint ("Found email - Opening..")
            emailvar.Display '<- Error is created from here
            Exit Sub
        End If
    Next emailvar

    Set searchFolder = Nothing
End Sub

这是因为它不能同时查看两封电子邮件吗?

【问题讨论】:

  • 也许明确定义您的电子邮件项目可能会有所帮助,例如:Dim emailvar As Outlook.MailItem,这需要添加对您最近的 Microsoft Outlook 库的引用...

标签: vba outlook mailitem


【解决方案1】:

所以最后的问题是,实际上我打开了 2 个视图实例。我没有花太多时间在上面,而是创建了一个看起来像电子邮件视图的用户表单,并从解析的 MailItem 对象中提取了详细信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-21
    • 1970-01-01
    • 2020-03-24
    • 2022-07-08
    • 1970-01-01
    相关资源
    最近更新 更多