I know that when you’re in menu “Customize” mode, you can drag a form from a list of forms onto a menu bar or sub menu and that will provide you with a menu option that will open the form.
But is it possible to do the same thing from code?
With cb set up as a CommandBar object I can execute
Set cbrButton = cb.Controls.Add(msoControlButton, , “dlgFormName”)
cbtButton.Caption = “dlgFormName”
and, barring the icon, the resulting menu item looks like, and at first glance appears to have the same properties as, one created by dragging the form onto the menu. But this one doesn’t do anything. It doesn’t error, but nothing happens when you click on it.
A closer look at the properties in code and I can find two differences. One is that the one I created in code has a BuiltIn value of false whereas the one dragged there has a BuiltIn value of true. But this is a readonly property, so I can’t explicitly set it in code.
The other property is the ID. While the one created in code has the default ID of 1, the ID of the dragged item is 1837. Now I know that you can add built-in items to custom menus by using the ID parameter in the Add command, but adding with an ID of 1837 produces an automation error when I try it. So something like this, for example
Set cbrButton = cb.Controls.Add(msoControlButton, 1837, “dlgFormName”)
cbtButton.Caption = “dlgFormName”
doesn’t work.
Does anyone know if what I’m trying to do is possible and, if so, what the trick is?