Worksheet Menu Bar

L

LAF

I commented out the Reset line and I also removed th
application.workbooks("wwgpe.xls") and it seems to be working.
However, when I switch between spreadsheets (our tool and another xl
file) and then go back to our tool, it keeps adding our customized men
item every time you go to our tool. Any ideas on how to prevent that?
We are calling code for the menu items in both the Activate an
DeActivate modules
 
R

Ron de Bruin

Hi Laf

If you create a menu item the best practice is to delete it first with a
on error code.

For example

Sub MenuBar_Item()
MenuBar_Item_Delete
With Application.CommandBars(1)
With .Controls.Add(Type:=msoControlButton, before:=1)
.Style = msoButtonCaption
.Caption = "&Hi"
.OnAction = ThisWorkbook.Name & "!TestMacro"
End With
End With
End Sub

Sub MenuBar_Item_Delete()
On Error Resume Next
Application.CommandBars(1).Controls("Hi").Delete
On Error GoTo 0
End Sub

Sub TestMacro()
MsgBox "Hi"
End Sub
 

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