Deleting custom menu item createt in VBA



Hi i've have a macro setting up a custom menu item in the Files, Send
To menu (ie in at submenu to the files menu).

The macro is set in the ThisWorkbook section but i cannot figure out
how to delete it again (i get multiple items of it).

The code looks like this:

' Code for creating the menu item
Sub InsertMenuItem()
Dim RowMenu As CommandBarControl
Dim NewMenuItem As CommandBarButton
'Find menuitem Row
Set RowMenu = CommandBars(1).FindControl(ID:=30095,
'Insert new menuitem (button)
Set NewMenuItem = RowMenu.Controls.Add(Type:=msoControlButton)
With NewMenuItem
.Caption = "Postmodtager (som vedhæftet PDF)..."
.FaceId = 5622
.OnAction = "SendPDFSomMail"
End With
End Sub

' Code for putting the item in the menu
Private Sub Workbook_Open()
MyNewMenu HideMe
End Sub

I know I have to put the code to delete it in an Workbook_BeforeClose
sub but cannot get anything to work. All examples i find is to delete
an entire menu and not a single menu item.

Any ideas?


BTW I would also like to be able to control where the menu item i
placed in the submenu. Now its added as the last item in the "Send To"
submenu but I would like it to be the 4th entry.

Is that possible.

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