View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] Spencer.Sadkin@gmail.com is offline
external usenet poster
 
Posts: 42
Default menu bar and error 91

hi, i wrote some code which is essentially the following and it gives
error 91 on due to the following line

CommandBars("worksheet menu bar").FindControl(ID:=30002).Copy
bar:=CommandBars("mymenu")

any ideas on how to fix it? thanks again.

this is the full code: 'note be sure not to save since the remove
bar macro is not in this code

Sub Create_MyMenu()
'Hide the Excel worksheet menu bar
Application.CommandBars(1).Enabled = False
'Remove MyMenu if it exists
On Error Resume Next
MenuBars("MyMenu").Delete
On Error GoTo 0
'Create a new blank menu bar called MyMenu
MenuBars.Add "MyMenu"
'Add menu items "Azri1", to the MyMenu bar
MenuBars("MyMenu").Menus.Add Caption:="Azri1"
CommandBars("worksheet menu bar").FindControl(ID:=30002).Copy
bar:=CommandBars("mymenu")
'Add menu items(macros) under the "Azri1" menu item.
With MenuBars("MyMenu").Menus("Azri1").MenuItems
..Add Caption:="&Macro1", OnAction:="Macro1"
..Add Caption:="&Macro2", OnAction:="Macro2"
'etc
End With
'Display the "MyMenu" menu bar
MenuBars("MyMenu").Activate
End Sub