Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Menus to Excel 1

Status
Not open for further replies.

snikde

Programmer
Mar 13, 2002
35
US
I bet this is an easy one, however damned if I can figure it.
I have the following code to add menus to a workbook upon opening it. From time to time, multiple versions of the same file are opened resulting in redundant menus. How can I check for a menus existence and not recreate it.

Guy


Sub Auto_Open()
AddAMenu
End Sub
Sub AddAMenu()
MenuBars(xlWorksheet).Menus.Add Caption:="Structure"
MenuBars(xlWorksheet).Menus("Structure").MenuItems.Add Caption:="Order By Assembly", OnAction:="ViewTree"
MenuBars(xlWorksheet).Menus("Structure").MenuItems.Add Caption:="Get Costing", OnAction:="GetCosts
 
Hi snikde,

Try this ...

Code:
[blue]Sub AddAMenu()

Dim Menu As Menu

On Error Resume Next
Set Menu = MenuBars(xlWorksheet).Menus("Structure")
On Error GoTo 0

If Menu Is Nothing Then
    Set Menu = Nothing
    MenuBars(xlWorksheet).Menus.Add Caption:="Structure"
    [green]' etc.[/green]
End If[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top