Pergunta

I have an Outlook macro and I'm working to convert it to a com add in to make deployment easier. This is my first attempt at doing this and I am using VSTO 2013. When I copy over the code I'm using in my macro, it doesn't like the "Outlook.Application.ActiveInspector.CurrentItem" as I get an error: "Reference to a non-shared member requires an object reference." The code I am using is listed below.

Sub InsertSubject()

Dim objMsg As Outlook.MailItem

'Get the currently open message'

Set objMsg = Outlook.Application.ActiveInspector.CurrentItem

objMsg.Subject = objMsg.Subject & "(Secure) "

'Destroy the object to avoid memory leaks'
objMsg.Send
Set objMsg = Nothing


End Sub

Can anyone give me some tips on how to use the currently selected item item in VB? Sorry if this comes aross as a "teach me how to code" question. I am new to this and just learn better when I have a real world problem to work through.

Foi útil?

Solução

I was actaully able to piece the following together and get this to work.

    Dim _item As Outlook.MailItem = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem

    Dim objMsg As Outlook.MailItem

    'Get the currently open message'
    objMsg = Globals.ThisAddIn.Application.ActiveInspector().CurrentItem

    objMsg.Subject = objMsg.Subject & "(Secure) "

    'Destroy the object to avoid memory leaks'
    objMsg.Send()
    objMsg = Nothing
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top