Chip/Doug,
I'm only a simple engineer not a programmer!! What I'm
trying to do is process engineering recording data from
multiple sources. In some cases there are several
different graphs that could be used, thus a popup menu is
appropriate. In other cases a simple Control button
suffices.
At present, I regenerate the menu structure when the
spreadsheet is openned or new data added. I'm not quite
ready to change the approach just yet!
Relevant code is as below. I'm using Excel 97 at home
and Excel 2000 at work.
Thanks in anticipation
Dim MyControls As CommandBarControl
Dim NewButton As CommandBarButton
Dim NewButtonCaption As String
Dim NewButtonAction As String
Dim SubMenu As Object
Dim SubMenuItem As Object
Dim SubMenuCaption1 As String
Dim SubMenuCaption2 As String
Dim SubMenuAction1 As String
Dim SubMenuAction2 As String
Sub Process_Synchro_Recordable_Signal_TRAIN
() 'Process Synchro Training data
etc
etc
NewButtonCaption = "Synchro Training"
SubMenuCaption1 = "Plot
Training" ' Submenu captions if required
SubMenuCaption2 = "Plot Normalised Training"
SubMenuAction1 = "Plot_Synchro_Training"
SubMenuAction2 = "Plot_Synchro_Training_Norm"
AddNewButton
End Sub
Sub AddNewButton()
Set MyControls = CommandBars.FindControl
(Tag:=NewButtonCaption) ' Check if custom button exists
If MyControls Is Nothing
Then ' If the button
does not exist then...
If SubMenuCaption1 = Empty
Then ' If only a single
action is required, create a Control Button for Worksheet
Set NewButton = CommandBars("Worksheet Menu
Bar").Controls("SWMLU").Controls.Add
(Type:=msoControlButton, Before:=1)
With NewButton
.BeginGroup = True
.Caption = NewButtonCaption
.Tag = NewButtonCaption
.FaceId = 0
.OnAction = NewButtonAction
End With
NewButton.Visible = True
ElseIf SubMenuCaption1 <> Empty Then
Set SubMenu = CommandBars("Worksheet Menu
Bar").Controls("SWMLU")
With SubMenu
.Controls.Add(Type:=msoControlPopup,
Before:=1).Caption = NewButtonCaption
End With
Set SubMenuItem = CommandBars("Worksheet
menu bar").Controls("SWMLU").Controls(NewButtonCaption)
With SubMenuItem
.Controls.Add(Type:=msoControlButton,
Before:=1).Caption = SubMenuCaption1
.Controls(SubMenuCaption1).OnAction =
SubMenuAction1
End With
End If
Else
Exit Sub ' Controls already
exist
End If