B
bob.eastman
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 Autpen()
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, _
Before:=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
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 Autpen()
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, _
Before:=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