Reference to a non-shared member requires an object reference? - Application.ActiveInspector RRS feed

  • Question

  • Hi

    Im getting into the hang of things, or rather i thought i was. My ultimate goal is to create a outlook add-in that will show a button on the new mail ribbon. When the button is pressed the words [ENCRYPTED] Pre-pended to the subject, it sets the email sensitivity to Confidential and then sends the email. Easy if you know how. I have so far managed to get the button working with Macros and dev tools in Outlook 2016. I hit a brick wall when i try use the VSTO, my code gives me errors specifically with the Encrypt and send sub. Here is my code:

        Public Shared Sub EncryptAndSend(ByVal control As Office.IRibbonControl)
            Dim Item As Microsoft.Office.Interop.Outlook.MailItem
            Item = Application.ActiveInspector.CurrentItem()
            Dim strSecure As String
            strSecure = "[Encrypted] " & Item.Subject
            Item.Subject = strSecure
        End Sub
    the line that is giving me an error is:
    Item = Application.ActiveInspector.CurrentItem()
    Here is the GUI image of the line being flagged up.

    I think i understand what i need to do but not sure how? I have changed the code countless times to make it work, but without really knowing what im doing, im not really achieving anything. 

    Any advice would be greatly appreciated. 



    Wednesday, February 14, 2018 4:57 PM


  • I managed to get this sorted with help from a friend. I had to change this:

    Item = Application.ActiveInspector.CurrentItem()

    To this:

    Item = Globals.ThisAddIn.Application.ActiveInspector.CurrentItem()

    I also had to remove "shared" from the sub.

    Not sure why but it works. Can anyone explain why this works? 



    Friday, February 16, 2018 12:39 PM