Solved

Outlook 2007 Add In - Visual Studio 2008 - Visual Basic

Posted on 2011-09-13
6
353 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Big Problem with Redirected Folder 8 40
How to get windows DNS resolve to internal address? 3 28
A Function to parse a text string 4 34
Interpreting a header of junk mail 8 123
Outlook Free & Paid Tools
In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
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 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: …

816 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

8 Experts available now in Live!

Get 1:1 Help Now