![]() |
Menu problem
In Sub MenuSetRangeSelectedOption() below, the macro crashes when it
gets to line Set TG1 = MenuItem.Controls("&RangeSelected"). Can anyone tell m,e what I am doing incortrectly tia bob Option Explicit Public TG1 As CommandBarButton Public TG2 As CommandBarButton Public bMenuRangeSelectedOption As Boolean Sub Auto_Open() Dim NewMenu As CommandBarPopup Dim HelpMenu As CommandBarControl Dim MenuItem As CommandBarControl Dim Submenuitem As CommandBarButton On Error Resume Next CommandBars(1).Controls("myTools").Delete ' Find the Help Menu Set HelpMenu = CommandBars(1).FindControl(ID:=30010) If HelpMenu Is Nothing Then 'Add the menu to the end Set NewMenu = CommandBars(1).Controls.Add _ (Type:=msoControlPopup, _ temporary:=True) Else 'Add the menu before Help Set NewMenu = CommandBars(1).Controls.Add _ (Type:=msoControlPopup, _ Befo=HelpMenu.Index, _ temporary:=True) End If ' Add a caption for the menu NewMenu.Caption = "&myTools" ' 8th MENU ITEM Set MenuItem = NewMenu.Controls.Add _ (Type:=msoControlPopup) With MenuItem .Caption = "&Options" .BeginGroup = True End With ' 8th MENU ITEM - FIRST SUBMENU ITEM Set Submenuitem = MenuItem.Controls.Add _ (Type:=msoControlButton) With Submenuitem .Caption = "&RangeSelected" .OnAction = "MenuSetRangeSelectedOption" End With bMenuRangeSelectedOption = True Set TG1 = MenuItem.Controls("&RangeSelected") TG1.State = msoButtonDown End Sub Sub MenuSetRangeSelectedOption() Set TG1 = MenuItem.Controls("&RangeSelected") MsgBox TG1 On Error Resume Next If bMenuRangeSelectedOption = False Then bMenuRangeSelectedOption = True TG1.State = msoButtonDown Else bMenuRangeSelectedOption = False TG1.State = msoButtonUp End If End Sub |
All times are GMT +1. The time now is 12:00 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com