ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Deleting custom menu item createt in VBA (https://www.excelbanter.com/excel-programming/430348-deleting-custom-menu-item-createt-vba.html)

HenrikH

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,
recursive:=True)
'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
InsertMenuItem
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?

HenrikH

Deleting custom menu item createt in VBA
 
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.



All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com