Hello,
I answer this with much trepidation. Not certain, based on limited info in question, that this is what you actually need. There is no mention of how or why you are doing this. Regardless I present some more info here and a sample.
The document you reference was posted over three years ago and I spent many weeks if not months just to get to that point. Had many problems with direct modification of menus, most ending with crashes. The purpose of user menus in this context is to modify the selections based upon something already done by the user - selecting an existing item, changing sheets/forms etc. Depending upon that the menu can add, delete or make unavailable items.
The document also explains many ways for access and your post shows an early method. The sample attached uses one mentioned later in the document after various problems were encountered.
Most of the menu items, sub menus and items in any menu are controlled by indexes. My sample uses hard coded numbers but you can replace these with variables. A sub menu is an offshoot of a menu. You must base its' creation on the previous menu item. So if the menu item is food defined:
'New menu
oPopupMenu = CreatePopupMenu( stMyPopupMenuCmdId, "Food", oMenuBarSettings )
' New Popup
oPopupMenuContainer = oPopupMenu(3).Value
and the first item is to be another container for more items, a popup within the popup must be created:
'Popup in Popup
' New Popup
oPopupMenu2 = CreatePopupMenu( stMyPopupMenuCmdId, "European", oMenuBarSettings )
' Add Popup to menu
oPopupMenuContainer.insertByIndex( 0, oPopupMenu2 )
From there you can add further popups or actual menu items.
The sample adds two main menu items and a sampling of sub menus and actual menu items which when clicked will display a message box.
Sample ----- MenuSample.ods
Edit:
To present an example of not using macros to create the menus, have quickly created a sample using Tools->customise...
Sample ------- MenuSampleUsingCustomise.ods
Still contains the macros to display the messages.
@lonk,
Not certain what your end goal is. When something is selected, what is supposed to happen?
Also, the impression was to modify menus on the fly. This would mean when an action takes place, it is cause to modify a menu. From what is seen on the surface here, macros are not needed to create the menu. You can create using
Tools->Customize
onMenu
tab.Please add further clarification.
Depending on result wanted you may also consider drop down boxes. See answer by Jim K in this post -> Drop down box and database range question.
In my answer, the link no longer exists but I still have the original sample.
@Ratslinger
Sorry for my short explanation in my question, I would like to create the menu when a specific Calc file starts and delete the menu again when it closes.
From hereunder code, I could add "Food"(with Submenu "European") and "Beverage" (with Submenu "Coffee") after "Help" menu. The target is to assign assign Macros to menu items with club signal. In Sheet1 is the plan that the menus will look like that.
@Ratslinger
@Ratslinger
@Ratslinger
@Ratslinger
Just got the message after posting an answer. Using icons was one of the problem areas of menu creation. If a menu item was based upon an uno command icons appeared without a problem provided certain settings were made. User commands presented a bigger problem. Had a little success but the icons would not generate upon menu creation. Could only get a display after successive selections of an item. In your example that will be most difficult.
As mentioned in the answer, there are many problems with direct access to menus and icons is just one of them.
Finally, after re-reading this comment, maybe you don't want the icons to appear after all. Anyway, now you know.
@Ratslinger
Thank you so much for your concern. And all icons (or FaceID) are not necessary.