ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   menu bar and error 91 (https://www.excelbanter.com/excel-programming/406900-menu-bar-error-91-a.html)

[email protected]

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


All times are GMT +1. The time now is 12:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com