I am designing a Addin for outlook that has a custom menuitem suppose, "MyMenuItem". I have added this new menu item and capturing the events by getting the reference of the new menuitem in a global variable "fMenuItem" declared as
Dim WithEvents fMenuItem As Office.CommandBarButton
Everything works fine if I am having a single window opened in an Outlook session. Now the problem arrises when new windows are opened, for example by double clicking the selected e-mail. At this point, a new instance of menu is created and keeping the reference of new one will loose the old refernce.
To sort out this I tried using OnAction property of CommandBarControl object. But unfortunatrly this is not working, I mean the function/sub specified for OnAction is not being invoked by clicking the menu item.
Can anybody help me sorting out this problem?
I have following code:
Dim cbCtrl As CommandBarControl
Dim cmdControl As CommandBarControl
Dim cbBtn As Office.CommandBarButton
' add stop MyMenuItem
Set cbCtrl = .Controls.Add(Type:=msoControlButton, Temporary:=True, Before:=2)
Set cbBtn = cbCtrl
.Style = msoButtonIconAndCaption
.FaceId = 228
.Caption = "MyMenuItem"
.Tag = .Caption
.ToolTipText = "This is MyMenuItem :-) "
.OnAction = "runme"
MsgBox " Run me called "
In summary the question is:
- I have menu Item Tools->MyMenuItem.
- This menu item is added to all the newly opened windows from withen the outlook session.
- I have to capture events from all the "MyMenuItem"
- How can this task be done?
Waiting for suggestions...