John,
Since you named the control, you can simply use:
Sub hideAbout()
Dim TPBQMenu As CommandBarPopup
Set TPBQMenu = CommandBars(1).Controls("&TPBQ")
TPBQMenu.Controls("&About TPBQ...").Enabled = False
End Sub
Sub showAbout()
Dim TPBQMenu As CommandBarPopup
Set TPBQMenu = CommandBars(1).Controls("&TPBQ")
TPBQMenu.Controls("&About TPBQ...").Enabled = True
End Sub
HTH,
Bernie
Excel MVP
"John" wrote in message ...
Chip, thanks for your help but I must be extreemly thick
as I am struggling with this for more than a day now and
it still doesn't work!!!
Would yuo mind to have a quick look where I go wrong.
Thanks and I really appreciate your help.
kind regards John
Option Explicit
Sub CreateMenu()
Dim HelpMenu As CommandBarControl
Dim NewMenu As CommandBarPopup
Dim MenuItem As CommandBarControl
Dim Submenuitem As CommandBarButton
Call DeleteMenu
Set HelpMenu = CommandBars(1).FindControl(ID:=30010)
If HelpMenu Is Nothing Then
Set NewMenu = CommandBars(1).Controls.Add
(Type:=msoControlPopup, temporary:=True)
Else
Set NewMenu = CommandBars(1).Controls.Add
(Type:=msoControlPopup, Befo=HelpMenu.Index,
temporary:=True)
End If
With NewMenu
.Caption = "&TPBQ"
.Tag = "myTag"
End With
Set MenuItem = NewMenu.Controls.Add
(Type:=msoControlButton)
With MenuItem
.Caption = "&New questionnaire..."
.FaceId = 18
.OnAction = "NewQuestionaire"
.BeginGroup = True
End With
Set MenuItem = NewMenu.Controls.Add
(Type:=msoControlButton)
With MenuItem
.Caption = "&About TPBQ..."
.OnAction = "DeleteMenu"
End With
End Sub
Sub DeleteMenu()
On Error Resume Next
CommandBars(1).Controls("TPBQ").Delete
End Sub
Sub hideAbout()
Dim TPBQMenu As CommandBarPopup
Set TPBQMenu = CommandBars(1).FindControl
(Type:=msoControlButton, Tag:="myTag")
TPBQMenu.Controls("&About TPBQ...").Enabled = False
End Sub
Sub showAbout()
Dim TPBQMenu As CommandBarPopup
Set TPBQMenu = CommandBars(1).FindControl
(Type:=msoControlButton, Tag:="myTag")
TPBQMenu.Controls("&About TPBQ...").Enabled = True
End Sub
-----Original Message-----
John,
When you create the menu item, assign some string to the
Tag
property, then use the Tag argument instead of the ID
argument in
the FindControl method. E.g.,
Set TPBQMenu = CommandBars(1).FindControl _
(Type:=msoControlButton, Tag:="TheTag")
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
"John" wrote in message
...
Dear all
I have custom menu that works OK but I do not seem to be
able to disable or enable seperate menu items.
I tried the following code but this gives an error
message:
Menu bar item: TPBQ
Sub DisMenuItems()
Dim TPBQMenu As CommandBarPopup
Set TPBQMenu = CommandBars(1).FindControl
(Type:=msoControlButton, ID:=CommandBars(1).Controls
("TPBQ").ID)
TPBQMenu.Controls("&Export...").Enabled = False
End Sub
Error message:
Runtime error 91:
Object variable or with block variable not set
I am using excel 2002 on win 2000
Any help would be really apppreciated
Kind regards,
John
.