how to get the object associated with a context menu in an office add-in
I have a simple COM add-in for office that I am developing (for access specifically).
I have added a custom commandbarbutton item to the context menu that pops up when you right click on an object in the navigation pane.
This works fine. The debug code I added runs (currently just a msgbox command). The one thing I cannot figure out how to do though is get an object for the object bound to the context menu.
I would like this to happen; I right click on a module in the navigation pane, select my new menu option, and then a message box appears with the name of the module that is currently highlighted. How would I go about this?
This is how I am currently handling the event:
Public Sub myEventHandler(ByVal ctrl As CommandBarButton, ByRef CancelDefault As Boolean) Handles contextMenu_navPaneObject.Click, contextMenu_navPaneList.Click
MsgBox(Microsoft.VisualBasic.Information.TypeName(ctrl) & vbCrLf & _
Microsoft.VisualBasic.Information.TypeName(ctrl.Parent) & vbCrLf & _
Microsoft.VisualBasic.Information.TypeName(ctrl.Parent.Parent))
End Sub
contextMenu_navPaneObject and contextMenu_navPaneList are private objects declared using "withevents" and having an object type of commandbarbutton.
I开发者_开发技巧s this the correct way to do what I want, or is there an alternative method I should be using?
Turns out to do what I wanted, I needed to run the following method:
Access.Application.CurrentObjectName()
This returned the name of the item I currently had highlighted.
I hope this helps others!
精彩评论