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:
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
To present an example of not using macros to create the menus, have quickly created a sample using
Sample ------- MenuSampleUsingCustomise.ods
Still contains the macros to display the messages.