menu bar and error 91

S

Spencer.Sadkin

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
 
J

Jim Rech

Sub Create_MyMenu ran perfectly for me.

I haven't memorized all the error message codes. What was the text of the
error message?

--
Jim
| 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
 
J

Jim Rech

If your code sits in a non-standard module be sure that "Application."
precedes "Commandbars".
 

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