J
jfcby
Hello,
I trying to create a toolbar with popups & buttons. I using the macro
below to:
1. Create the toolbar
2. Add Popup menus with buttons
3. Add more buttons to hte main toolbar
My macro will not all multiple buttons to the Popup menus. How can I
add multiple buttons the the popup menus without using several with
statements?
<MACRO CODE BEGIN>
Rem ****BEGIN**** Command / Tool Bar ************
Function TBN() As Variant
'Tool Bar Name
TBN = "ToolBar Example Test"
End Function
Sub CreateOtherCommandBar()
'
Dim i As Variant, j As Variant
Dim cPopup(1 To 9)
Dim macs(1 To 9, 1 To 9), caps(1 To 9, 1 To 9), tips(1 To 9, 1 To 9)
'Main Toolbar Control Popup Menus
cPopup(1) = "Column Options"
cPopup(2) = "Row Options"
cPopup(3) = "Sort Options"
'Main & Sub Toolbar Buttons
'Column Options
macs(1, 1) = "CTB1"
macs(1, 2) = "CTB2"
macs(1, 3) = "CTB3"
'Row Options
macs(2, 1) = "CTB1"
macs(2, 2) = "CTB2"
'Sort Options
macs(3, 1) = "CTB1"
macs(3, 2) = "CTB1"
'Main Toolbar Button Macros
macs(4, 1) = "MTB1"
macs(4, 2) = "MTB2"
'Column Options
caps(1, 1) = "H/U Col"
caps(1, 2) = "I/D Col"
caps(1, 3) = "Move Col"
'Row options
caps(2, 1) = "H/U Row"
caps(2, 2) = "I/D Row"
'Sort Options
caps(3, 1) = "Sort Asc"
caps(3, 1) = "Sort Dsc"
'Main Toolbar Button Captions
caps(4, 1) = "MTB1"
caps(4, 2) = "MTB2"
'Column Tips
tips(1, 1) = "H/U Col"
tips(1, 2) = "I/D Col"
tips(1, 3) = "Move Col"
'Row Tips
tips(2, 1) = "H/U Col"
tips(2, 2) = "I/D Col"
tips(2, 3) = "Move Col"
'Sort tips
tips(3, 1) = "H/U Col"
tips(3, 2) = "I/D Col"
tips(3, 3) = "Move Col"
'Main Toolbar Button Tips
tips(4, 1) = "H/U Col"
tips(4, 2) = "I/D Col"
tips(4, 3) = "Move Col"
'Delete Toolbar
DeleteOtherCommandBar
'Create Toolbar
With Application.CommandBars.Add
.Name = TBN
.Visible = True
For i = LBound(caps, 1) To UBound(caps, 1)
For j = LBound(caps, 2) To UBound(caps, 2)
If caps(i, j) <> "" Then
'Create Popup Menus
With .Controls.Add(Type:=msoControlPopup)
If j = i Then .Caption = cPopup(i)
With .Controls.Add(Type:=msoControlButton)
.OnAction = ThisWorkbook.Name & "!" & macs(i, j)
.cPopup(i).Caption = caps(i, j)
.cPopup(i).TooltipText = tips(i, j)
End With
End With
'Create Buttons
If i >= 4 Then
With .Controls.Add(Type:=msoControlButton)
.OnAction = ThisWorkbook.Name & "!" & macs(i, j)
.Caption = caps(i, j)
.TooltipText = tips(i, j)
.Style = msoButtonIconAndCaption
End With
End If
End If
Next j
Next i
End With
End Sub
Sub DeleteOtherCommandBar()
'Toolbar name is defined above in Function TBN _
& can be changed
On Error Resume Next
Application.CommandBars(TBN).Delete
On Error GoTo 0
End Sub
<MACRO CODE END>
Thank you for your help,
jfcby
I trying to create a toolbar with popups & buttons. I using the macro
below to:
1. Create the toolbar
2. Add Popup menus with buttons
3. Add more buttons to hte main toolbar
My macro will not all multiple buttons to the Popup menus. How can I
add multiple buttons the the popup menus without using several with
statements?
<MACRO CODE BEGIN>
Rem ****BEGIN**** Command / Tool Bar ************
Function TBN() As Variant
'Tool Bar Name
TBN = "ToolBar Example Test"
End Function
Sub CreateOtherCommandBar()
'
Dim i As Variant, j As Variant
Dim cPopup(1 To 9)
Dim macs(1 To 9, 1 To 9), caps(1 To 9, 1 To 9), tips(1 To 9, 1 To 9)
'Main Toolbar Control Popup Menus
cPopup(1) = "Column Options"
cPopup(2) = "Row Options"
cPopup(3) = "Sort Options"
'Main & Sub Toolbar Buttons
'Column Options
macs(1, 1) = "CTB1"
macs(1, 2) = "CTB2"
macs(1, 3) = "CTB3"
'Row Options
macs(2, 1) = "CTB1"
macs(2, 2) = "CTB2"
'Sort Options
macs(3, 1) = "CTB1"
macs(3, 2) = "CTB1"
'Main Toolbar Button Macros
macs(4, 1) = "MTB1"
macs(4, 2) = "MTB2"
'Column Options
caps(1, 1) = "H/U Col"
caps(1, 2) = "I/D Col"
caps(1, 3) = "Move Col"
'Row options
caps(2, 1) = "H/U Row"
caps(2, 2) = "I/D Row"
'Sort Options
caps(3, 1) = "Sort Asc"
caps(3, 1) = "Sort Dsc"
'Main Toolbar Button Captions
caps(4, 1) = "MTB1"
caps(4, 2) = "MTB2"
'Column Tips
tips(1, 1) = "H/U Col"
tips(1, 2) = "I/D Col"
tips(1, 3) = "Move Col"
'Row Tips
tips(2, 1) = "H/U Col"
tips(2, 2) = "I/D Col"
tips(2, 3) = "Move Col"
'Sort tips
tips(3, 1) = "H/U Col"
tips(3, 2) = "I/D Col"
tips(3, 3) = "Move Col"
'Main Toolbar Button Tips
tips(4, 1) = "H/U Col"
tips(4, 2) = "I/D Col"
tips(4, 3) = "Move Col"
'Delete Toolbar
DeleteOtherCommandBar
'Create Toolbar
With Application.CommandBars.Add
.Name = TBN
.Visible = True
For i = LBound(caps, 1) To UBound(caps, 1)
For j = LBound(caps, 2) To UBound(caps, 2)
If caps(i, j) <> "" Then
'Create Popup Menus
With .Controls.Add(Type:=msoControlPopup)
If j = i Then .Caption = cPopup(i)
With .Controls.Add(Type:=msoControlButton)
.OnAction = ThisWorkbook.Name & "!" & macs(i, j)
.cPopup(i).Caption = caps(i, j)
.cPopup(i).TooltipText = tips(i, j)
End With
End With
'Create Buttons
If i >= 4 Then
With .Controls.Add(Type:=msoControlButton)
.OnAction = ThisWorkbook.Name & "!" & macs(i, j)
.Caption = caps(i, j)
.TooltipText = tips(i, j)
.Style = msoButtonIconAndCaption
End With
End If
End If
Next j
Next i
End With
End Sub
Sub DeleteOtherCommandBar()
'Toolbar name is defined above in Function TBN _
& can be changed
On Error Resume Next
Application.CommandBars(TBN).Delete
On Error GoTo 0
End Sub
<MACRO CODE END>
Thank you for your help,
jfcby