PC Review


Reply
Thread Tools Rate Thread

Adding a new menu on the Worksheet menu bar

 
 
u473
Guest
Posts: n/a
 
      25th Nov 2009
I tried to adapt J.Walkenbach code to add a menu item on Workbook_open
but I get the following error on "HelpIndex = CommandBars(1).Controls
("Help").Index"
Run-time Error '91'
Object variable or with block variable not set

Private Sub Workbook_Open()
Dim HelpIndex As Integer
Dim NewMenu As CommandBarPopup
' Get Index of Help menu
HelpIndex = CommandBars(1).Controls("Help").Index
' Create the control
Set NewMenu = CommandBars(1) _
.Controls.Add(Type:=msoControlPopup, Before:=HelpIndex,
Temporary:=True)
' Add a caption
NewMenu.Caption = "Fi&lter"
End Sub

Help appreciated,
J.P.
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      25th Nov 2009
If you use a non English version it is possible that the Help label not exist

You can use the ID number of the control

See
http://www.rondebruin.nl/international.htm#Command


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"u473" <(E-Mail Removed)> wrote in message news:7fe41e9d-49fc-4ce0-aea6-(E-Mail Removed)...
>I tried to adapt J.Walkenbach code to add a menu item on Workbook_open
> but I get the following error on "HelpIndex = CommandBars(1).Controls
> ("Help").Index"
> Run-time Error '91'
> Object variable or with block variable not set
>
> Private Sub Workbook_Open()
> Dim HelpIndex As Integer
> Dim NewMenu As CommandBarPopup
> ' Get Index of Help menu
> HelpIndex = CommandBars(1).Controls("Help").Index
> ' Create the control
> Set NewMenu = CommandBars(1) _
> .Controls.Add(Type:=msoControlPopup, Before:=HelpIndex,
> Temporary:=True)
> ' Add a caption
> NewMenu.Caption = "Fi&lter"
> End Sub
>
> Help appreciated,
> J.P.

 
Reply With Quote
 
u473
Guest
Posts: n/a
 
      25th Nov 2009
"Help" ID is 30010
I tried to replace
HelpIndex = CommandBars(1).Controls("Help").Index
with
HelpIndex = CommandBars(1).Controls(ID:=30010).Index
I does not work.
I am working with a US Version of Excel 2003
and the original code comes from
Excel VBA Programming for Dummies from J. Walkenbach, page 314.
Where did I go wrong ?
Thank you for your response.
J.P.
 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      25th Nov 2009
This basic test is working for me

Sub MenuBar_Item()
Call MenuBar_Item_Delete
With Application.CommandBars(1)
With .Controls.Add(Type:=msoControlButton, before:=Application.CommandBars.FindControl(, 30010).Index)
.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



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"u473" <(E-Mail Removed)> wrote in message news:d491b62e-5779-45b2-b6b1-(E-Mail Removed)...
> "Help" ID is 30010
> I tried to replace
> HelpIndex = CommandBars(1).Controls("Help").Index
> with
> HelpIndex = CommandBars(1).Controls(ID:=30010).Index
> I does not work.
> I am working with a US Version of Excel 2003
> and the original code comes from
> Excel VBA Programming for Dummies from J. Walkenbach, page 314.
> Where did I go wrong ?
> Thank you for your response.
> J.P.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA:programmatically invoking menu items from Excel Worksheet menu =?Utf-8?B?bW9yc2UxMDA=?= Microsoft Excel Programming 15 29th Oct 2010 07:29 PM
Adding Custom Menu Items to the Right-Click Menu Nathan Sokalski Windows XP Configuration 1 3rd Feb 2005 04:41 AM
Re: Adding a menu item right click menu when clicking on a single. Frank Kabel Microsoft Excel Programming 1 2nd Sep 2004 10:23 PM
Adding custom menu items to Context menu mookashi Microsoft Outlook VBA Programming 1 17th Feb 2004 06:32 AM
problem adding button to an EXISTING dropdown menu on a Worksheet Menu Bar Karen P Microsoft Excel Worksheet Functions 3 29th Oct 2003 12:42 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:03 AM.