Dynamic Shortcut Menus with VBA (in COM Add-In)

G

Guido Erlinger

Hello,

I tried:

- It is possible to create programmatically with VBA
(in a COM Add-In) a shortcut menu
- It is also possible to show this with the .PopUp
method

- But I did not figure it out, how I can catch the
events of this menu. I do not know how much entries
the menu will have ...

Does someone know a way to do this?

cu Guido
 
K

Ken Slovak - [MVP - Outlook]

For what application?

In Outlook when I want a dynamic menu that adds buttons as needed I use a
button wrapper class with a code module to add instances of the class to a
collection. The menu is a CommandBarPopup control and I add to that object's
Controls collection CommandBarButton or even additional CommandBarPopup
controls as needed. The collection and class wrapper make sure that each
button fires its own click event handler and not one of the others (you need
a unique Tag property for each control you add to make this work).

An example:

'class module

Private WithEvents cbButton As Office.CommandBarButton

'init code and terminate code here in class events

'init button code here

Private Sub cbButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)

'button code here

End Sub

When you are called to create a new button you instantiate an instance of
the class module and add it to a buttons collection.
 
G

Guido Erlinger

Hello Ken,

Thank you for the answer!!!!

For what application?
FrontPage

I use a button wrapper class with a code module to add instances
of the class to a collection.

aaaaaah! Yes! That should work!
Thank you for this tip! I am working a lot with classes and so
this hint will help to simplify the code a lot :)

cu, Guido
 

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