Add Item to Context Menu

M

Muppidi

Hi

i need to addd an item to the existinfg Context Menu (right click on
outloook mail)

the item should be "Status" and its sub-items are "Approve" & "Reject"

Upon selecting "Approve", i should be able to update a field in my databse
to 1 (and 0 for "Reject")

any help....?

i'm using Outlook 2007, VS 2005.

Thanks & Regards,
Muppidi.
 
K

Ken Slovak - [MVP - Outlook]

At least in this copy of your 5 messages posted here with the same question
you finally provided the needed information on your Outlook version. One
post would have been enough.

Using Outlook 2007 you can use the Application.ItemContextMenuDisplay()
event to add your custom menu entry. Open the Outlook 2007 VBA project and
in the Object Browser select that event and click F1 for more information on
how to use that event.
 
M

Muppidi

Sorry Ken.
I got connection failure error when i was trying to post this.
i've made 5 attempts and the final one worked out.
but after that i saw 5 queries were posted.
did not find any link to delete the extra queries.

Coming to the point.
i'm getting VBA sample code thru google.
can u suggest a link or some sample code to use ItemContextMenuDisplay thru
C# or VB.Net.
Thanks & Regards,
Muppidi.
 
K

Ken Slovak - [MVP - Outlook]

I don't know any links to managed code for that event handler, but it's
trivial to translate VBA code to VB.NET code. You can also look at the
sample addins from MS on the Office developer site, those are in both VB.NET
and C# and if I recall correctly the sample one for the rules addin and
maybe the travel agency one have context menu code.
 
M

Muppidi

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 context menu
is getting added with my customized item.

this is the code:

Private Sub Application_ItemContextMenuDisplay(ByVal CommandBar As
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 to Office dll
also.
still i'm not able to see my item in the context menu.
waiting for ur reply.

Thanks & regards,
Muppidi
 
K

Ken Slovak - [MVP - Outlook]

Where are you running this code, it looks like it's in a VS project? How are
you adding the event handler?

If you aren't getting compilation errors then you don't need any additional
references. If your event handler isn't being called I'd suspect it isn't
being added correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top