Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default enabling custom meu items?

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 176
Default enabling custom meu items?

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



.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enabling Macros Nikhil Excel Worksheet Functions 1 July 9th 08 12:47 PM
Custom Calculated Items in a PivotTable JennyC Excel Worksheet Functions 1 January 12th 07 04:10 PM
Bold certain items in custom number format Sloth Excel Discussion (Misc queries) 0 August 25th 06 04:09 PM
Enabling sub menu items via vba Dan Neely Excel Worksheet Functions 0 July 11th 05 04:48 PM
Enabling macros Pennington Excel Worksheet Functions 1 December 2nd 04 07:43 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"