Solved

Outlook 2007 Add In - Visual Studio 2008 - Visual Basic

Posted on 2011-09-13
6
373 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
Scamming the Scammers!

Have you ever heard of Scam Baiting?
It's a highly entertaining sport that you can participate in.
Introduction to beating scammers at their own game and how you can help
Share your thoughts, ideas and experiences on the topic.
Links to top Anti-Scam resources provided.

 
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

RoboForm Secure Password Management System

RoboForm Everywhere - Superb Browser Support
Windows / Apple / IOS / Android / Linux / Chrome OS
Use different complex passwords everywhere
Best Secure Password Management by far
Synchronize all of your devices instantly
Safe, Secure & Highly Recommended!

Question has a verified solution.

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

Read this checklist to learn more about the 15 things you should never include in an email signature.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

739 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