首页 > 解决方案 > 设置停靠在主窗口中的电子邮件的 MailItem.Sensitivity

问题描述

尝试在 Outlook 2016 中停靠时设置活动 MailItem 的敏感度时出现以下错误。弹出电子邮件时,我的代码的“Else”部分有效。

Error message: 
Run-time error "-2082340855 (83e20009)

该对象不支持此方法。

您可以从我附加的屏幕截图中清楚地看到 msg 变量显然是一个“MailItem”。

在此处输入图像描述

更新:这是工作代码:

Sub ToggleConfidentialSensitivity()
    On Error Resume Next

    Dim msg As Outlook.MailItem

    If Application.ActiveInspector Is Nothing Then 'we are in the main window (inline)
        Set msg = Application.ActiveExplorer.ActiveInlineResponse
    Else 'we are in a popped out message
        Set msg = ActiveInspector.CurrentItem
    End If

    If msg.Sensitivity = olConfidential Then
        msg.Sensitivity = olNormal
        msg.Subject = Replace(msg.Subject, "*Confidential* ", "")
        MsgBox ("This email is now marked as public")
    Else
        msg.Sensitivity = olConfidential
        msg.Subject = "*Confidential* " + msg.Subject
        MsgBox ("This email is now marked as Confidential")
    End If
End Sub

标签: vbaoutlookoutlook-2016

解决方案


移到Dim msgif 语句之外。

如果您发布代码以便我们运行测试,将会很有帮助。

尝试类似 Select Case 示例

Select Case Application.ActiveWindow.Class
       Case olExp
            Set Msg = ActiveExplorer.selection.Item(1)
       Case olInsp
            Set msg = ActiveInspector.CurrentItem
End Select

推荐阅读