Solved

Outlook 2007 Add In - Visual Studio 2008 - Visual Basic

Posted on 2011-09-13
6
368 Views
Last Modified: 2012-05-12
HI,

I've been struggling to get certain parts of a visual basic script to run after creating the add in.

The add in that I've created is ready and working correctly. The only issue that I have is that when I run the add in, i am not able to read and append the contents of the subject line of the email that is being composed.

All the coding examples that I have seen so far start by referencing Application.CurrentItem, but the button's on click event is stored in a Ribbon.vs file and not the ThisAddIn.vs file.

Would anybody be able to help me to get my coding to read from the subject line and either append text or remove text if it is found.

I just need the few lines that will get the current subject of a new mail item being composed into a string.
0
Comment
Question by:BowmanGilfillan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36534045
Instead of Application.CurrentItem try

application.ActiveExplorer.Selection(1) ' for the currently selected item
or
application.ActiveInspector.CurrentItem.subject' for the currently open item

Chris
0
 

Author Comment

by:BowmanGilfillan
ID: 36535020
HI,

Thanks for that.

I still seem to be having a little bit of an issue.... here is my coding. I have two subs .... one for when the button is pressed and another one that does the work.... maybe you can find an issue with my coding?


 
Public Sub inspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles inspectors.NewInspector

        MessageBox.Show("Entered Function", "In Function", MessageBoxButtons.OK)

        Dim mailItem As Outlook.MailItem

        MessageBox.Show("set mailitem", "In Function", MessageBoxButtons.OK)

        If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then

            MessageBox.Show("Typeof If", "In Function", MessageBoxButtons.OK)

            mailItem = TryCast(Inspector.CurrentItem, Outlook.MailItem)

            MessageBox.Show("trycast done", "In Function", MessageBoxButtons.OK)


            'mi.Recipients
        End If

        'TryCast(Inspector.Application.CreateItem(Inspector.CurrentItem), Outlook.MailItem)

        'Inspector.CurrentItem, Outlook.MailItem)
        '       Me.Application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem), Outlook.MailItem

        MessageBox.Show("set mailitem", "In Function", MessageBoxButtons.OK)

        If Not (mailItem Is Nothing) Then

            MessageBox.Show("entered first if", "In Function", MessageBoxButtons.OK)

            If mailItem.EntryID Is Nothing Then

                MessageBox.Show("entered second if", "In Function", MessageBoxButtons.OK)

                mailItem.Subject = "<INS>" & mailItem.Subject

                MessageBox.Show(mailitem.Subject, "In Function", MessageBoxButtons.OK)

            End If
        End If
    End Sub

    ''' <summary>
    ''' Outlook will call this method when the btnWeb button is clicked.
    ''' </summary>
    Public Sub btnBGBanSup_OnAction(ByVal control As Office.IRibbonControl)

        MessageBox.Show("Button Pressed ...Entering Function", "Step One", MessageBoxButtons.OK)

        inspectors_NewInspector(inspectors.Application.ActiveExplorer.Selection)

    End Sub

Open in new window

0
 

Author Comment

by:BowmanGilfillan
ID: 36535026
I Seem to be having an issue around the typecast function if I pass "Inspectors" to the "working sub" and if I pass inspectors.Application.ActiveExplorer.Selection or (1) after selection" the whole "working sub" does not get called at all.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 36535169
Stick with the inspectors since it is new inspector function however when triggering it are you opening a mail item or for example a report ... Because if it is a mail item then a quick look shows no problem ... Though I am not skilled with interop

Chris
0
 

Accepted Solution

by:
BowmanGilfillan earned 0 total points
ID: 36535176
The below code works like a charm...
Dim BanSupp As MailItem = (control.Context).CurrentItem


        If (InStr(BanSupp.Subject, "<INS>") > 0) Then

            BanSupp.Subject = Replace(BanSupp.Subject, "<INS>", "")

        End If


        BanSupp.Subject = BanSupp.Subject & "<INS>"

Open in new window

0
 

Author Closing Comment

by:BowmanGilfillan
ID: 36558719
different coding that works for outlook 2007 ribbon
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question