Solved

Outlook 2007 Add In - Visual Studio 2008 - Visual Basic

Posted on 2011-09-13
6
335 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now