Thank you Anatoly. I changed the code to what is displayed below.
However ... the debug line that displays the menu.ApplicationContext ALWAYS displays "Main", regardless of what menu or sub-menu is opened. EXCEPT for the top-level Account menu in the menubar. In this case, it displays "Portfolio".
Thus, MY menu item is added to every single menu I go to (LOL).
I'm assuming that menu.ApplicationContext SHOULD be returning the name of each individual context menu, right?
I'm also assuming that menu.IsContextMenu() should ONLY be True when a right-click menu is displayed, yes? However, it's True for every single menu in the program (all menus in the menubar, etc.).
Thank you,
-Don
<pss_extension name="Context Menus" version="1.0">Context Menus
<script language="VBScript">
<![CDATA[
Class MyCMFormHandler
'-----------------------------------------------------------------------------
public Function OnMenuItemSelected ( id )
'-----------------------------------------------------------------------------
If id = G_MyContextMenuID Then
MsgBox "Code would be placed here to perform the necessary " _
& "function", vbOKOnly, "Message"
Exit Function
End If
End Function ' OnMenuItemSelected
'-----------------------------------------------------------------------------
public Function OnMenuPopup ( menu )
'-----------------------------------------------------------------------------
' Make sure the menu is a context menu ...
Application.DebugTrace "menu.IsContextMenu() = '" _
& CStr(menu.IsContextMenu()) & "'"
If menu.IsContextMenu() Then
Application.DebugTrace "menu.ApplicationContext = '" _
& CStr(menu.ApplicationContext) & "'"
If ( CStr(menu.ApplicationContext) = "Main" ) Then
Set ContextMenu = menu
' Add our menu item to the context menu if it doesn't already exist ...
nContextMenu = ContextMenu.Find("Get Data")
If (nContextMenu = -1) Then
ContextMenu.InsertSeparator ContextMenu.ItemCount
FormHandler.G_MyContextMenuID = ContextMenu.InsertItem(ContextMenu.ItemCount, "Get Data")
Else
Exit Function
End If
End If
End If
End Function ' OnMenuPopup
'-----------------------------------------------------------------------------
' Define Global Variables ...
'-----------------------------------------------------------------------------
Dim G_MyContextMenuID
End Class ' MyCMFormHandler
'-----------------------------------------------------------------------------
' Initialization ...
'-----------------------------------------------------------------------------
' Get the Event & Menu Manager objects ...
Set EventManager = Application.GetObject("EventManager")
Set MenuManager = Application.GetObject("MenuManager")
' Create a new FormHandler object ...
Set FormHandler = new MyCMFormHandler
' Set this global variable for first-time-through ...
G_MyContextMenuID = 0
' Register our event handlers ...
If (Not EventManager Is Nothing) Then
EventManager.RegisterHandlerMethod FormHandler, "OnMenuItemSelected"
EventManager.RegisterHandlerMethod FormHandler, "OnMenuPopup"
Else
' Could not get EventManager object.
End If
]]>
</script>
</pss_extension>