how to permantly delete a custom menu in excel

L

lostwings

hi,

I met a very strange problem with Excel.

Firstly I created a custom menu using the following VBA snippet

Sub add_menu()
Dim cmd_Bar As CommandBar
Dim menu_Intranet As CommandBarControl
Set cmd_Bar = Application.CommandBars("Worksheet Menu Bar")
Set menu_Intranet = cmd_Bar.Controls.Add(Type:=10, Temporary:=True)
menu_Intranet.Caption = "Intranet Entry"
End Sub

Then a custom menu appeared on the run time. However, after I closed the
excel, and reopened it without running any VBA Code, the same menu appeared,
which is very surprising. Then I used the following code to programmtically
delete the menu,

Sub delete_menu()
Dim cmd_Bar As CommandBar
Dim menu_Intranet As CommandBarControl

Set cmd_Bar = Sheet1.Application.CommandBars("Worksheet Menu Bar")
For Each menu_Intranet In cmd_Bar.Controls
If menu_Intranet.Caption = "Intranet Entry" Then
menu_Intranet.Delete
End If
Next
End Sub

Although such code can delete the menu on the run time as expected, when I
close and reopne excel, the custom menu is still then.

I would greatly appreciate if anyboday can tell me how to persuade this
little baby to diappear permantly. Thanks in advance.
 

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

Top