Custom Add-In for Outlook Mail

  • Thread starter Thread starter pavanmuppidi
  • Start date Start date
P

pavanmuppidi

Hi

When i right click on a Outlook Mail, along with the other existin
options i need to get one option like "Status" under which tw
sub-options like "Approve" and "Reject" should be there.

Upon selecting the Approve or Reject option, i should be able t
automatically update a field in my database as "1" for Approve and "0
for Reject.

Can anyone help me in this regard.

Thanks in advance.

Regards,
Muppidi
 
Outlook version?

For Outlook 2003 or earlier you can hack something that will fire when an
item in the folder view (Explorer) is clicked, but you won't be able to tell
which item was clicked or even if the click was on an item or somewhere else
like the Navigation Pane. So that's pretty useless for what you want.

For Outlook 2007 there are new context menu events that fire from the
Application object, the one you'd want would be the ItemContextMenuDisplay()
event. That tells you which item or items were selected when the right-click
occurred. See the Object Browser Help on that event to see how it works.
 
Yes, that's exactly what you need to use and the link has VBA code to use
the event. Have you tried pasting that code into your VBA project and
modifying it and then testing with that?

What errors are you getting? Did you try translating that VBA sample code to
whatever language you're using (either VB.NET or C#)? What code are you
trying to use?
 
Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar A
Office.CommandBar, ByVal Selection As Selection)

Static intCounter As Integer

On Error GoTo ErrRoutine

' Increment or reset the counter
If intCounter < 1 Or intCounter > 100 Then
intCounter = 1
Else
intCounter = intCounter + 1
End If

' Add the menu.
Dim objMenu As Object
objMenu = CommandBar.Controls.Add(msoControlButton)
objMenu.Caption = "Displayed " & intCounter & " times"
objMenu.Enabled = False
objMenu.BeginGroup = True

EndRoutine:
On Error GoTo 0
Exit Sub

ErrRoutine:
MsgBox(Err.Number & " - " & Err.Description, _
vbOKOnly Or vbCritical, _
"Application_ItemContextMenuDisplay")

GoTo EndRoutine
End Sub

i'm getting error at

1) "Selection" (Type Selection is not defined)
2) "msoControlButton" (msoControlButton name not defined.)

i would like to do this in C#.Net. (or VB.Net)

could u suggest me to resolve this.

Regards,
Muppidi
 
Where did you put that code? Is it in the Outlook VBA project? You need to
make sure that you have project references set to Outlook and to Office, and
that the Outlook reference is ahead of any other application that exposes a
Selection object or collection.

You can also just fully qualify the code by changing Selection to
Outlook.Selection and changing msoControlButton to
Office.MsoControl.msoControlButton.
 
HI
i was able to debug without any errors now.
but this is just opening the outlook and going out of debug mode.
thats it.
its not hitting the break points.
i'm using only the ItemContextMenuDisplay event only.
how to go into debug mode and check whether the selected item's contex
menu is getting added with my customized item.

this is the code:

Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar A
Office.CommandBar, ByVal Selection As Outlook.Selection)

Static intCounter As Integer

On Error GoTo ErrRoutine

' Increment or reset the counter
If intCounter < 1 Or intCounter > 100 Then
intCounter = 1
Else
intCounter = intCounter + 1
End If

' Add the menu.
Dim objMenu As Microsoft.Office.Core.CommandBarControl
Dim cmbBar As Microsoft.Office.Core.CommandBar

objMenu
cmbBar.Controls.Add(Office.MsoControlType.msoControlButton)
objMenu.Caption = "Displayed " & intCounter & " times"
objMenu.Enabled = True
objMenu.BeginGroup = True

EndRoutine:
On Error GoTo 0
Exit Sub

ErrRoutine:
MsgBox(Err.Number & " - " & Err.Description, _
vbOKOnly Or vbCritical, _
"Application_ItemContextMenuDisplay")

GoTo EndRoutine
End Sub

please tell me what i'm missing.
what else events i need to add...?
i've given the references to Outlook 11.0 & 12.0 dlls and also t
Office dll also.
still i'm not able to see my item in the context menu.
waiting for ur reply.

Thanks & regards,
Muppid
 
This is the same message you posted in the forms group. Please let's just
keep this to one thread in one group.

If the code compiles without errors and the event isn't being fired then you
aren't adding the event correctly. How are you adding the event?
 
Imports System
Imports System.Windows.Forms
Imports Microsoft.VisualStudio.Tools.Applications.Runtime
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Office = Microsoft.Office.Core

public class ThisApplication
Private m_objApp As Outlook.Application = Nothing

Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Me.Startup
AddHandler m_objApp.ItemContextMenuDisplay, AddressOf
Application_ItemContextMenuDisplay



End Sub

Private Sub ThisApplication_Shutdown(ByVal sender As Object, ByVal
e As System.EventArgs) Handles Me.Shutdown
End Sub

Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar As
Office.CommandBar, ByVal Selection As Outlook.Selection)

Static intCounter As Integer

On Error GoTo ErrRoutine

' Add the menu.
If Selection.Count > 0 Then
Dim mail As Outlook.MailItem
mail = Selection(1)

Dim objMenu As Office.CommandBarButton

objMenu =
CommandBar.Controls.Add(Office.MsoControlType.msoControlButton)
objMenu.Caption = "Displayed times"
objMenu.Enabled = True
objMenu.Visible = True

objMenu.BeginGroup = True

End If
EndRoutine:
On Error GoTo 0
Exit Sub

ErrRoutine:
MsgBox(Err.Number & " - " & Err.Description, _
vbOKOnly Or vbCritical, _
"Application_ItemContextMenuDisplay")

GoTo EndRoutine
End Sub


This is the code i'm using now. when i build the setup its getting
created. but the event is not getting fired. let me know if i'm missing
anything.

Regards,
Muppidi.
End Class
 
Where are you instantiating your m_objApp object?

You are assigning an event handler to that object before it's ever
instantiated, assigned to an object that's Nothing.

In your startup event handler assign the Me.Application value to your
Outlook.Application object:

m_objApp = Me.Application

Do that before you assign the event handler.
 
Back
Top