1

I am getting the following error when trying to set the Sensitivity of the active MailItem when docked in Outlook 2016. The "Else" part of my code works when the email is popped out.

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

The object does not support this method.

You can clearly see from my attached screenshot that the msg variable is clearly a "MailItem".

enter image description here

UPDATE: Here is the working code:

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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
BeYourOwnGod
  • 2,345
  • 7
  • 30
  • 35

2 Answers2

2

Move Dim msg outside if statement.

It would be helpful if you post your code so we can run a test.

Try something like Select Case example

Select Case Application.ActiveWindow.Class
       Case olExp
            Set Msg = ActiveExplorer.selection.Item(1)
       Case olInsp
            Set msg = ActiveInspector.CurrentItem
End Select
0m3r
  • 12,286
  • 15
  • 35
  • 71
  • 1
    Thanks for the suggestion. I will give that a try. I updated my question with my code so that you/others can test. – BeYourOwnGod Apr 10 '19 at 15:34
1

By "docked", do you mean an inline reply? In that case, you need to use Application.ActiveExplorer.ActiveInlineResponse to retrieve the MailItem object being composed.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78