Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Outlook 2007 Add In - Visual Studio 2008 - Visual Basic

Posted on 2011-09-13
6
Medium Priority
?
393 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Mailbox Overload?
This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

927 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