Tom,
The With/End With pair allows you to refer to multiple properties of the
control without specifying the control over and over. So here, we
repeatedly set the cbb variable to the most recently added button and then
use the With/End With to refer to 4 properties of that button. Here is how
the code should go:
Sub MakeBar()
Dim cb As CommandBar
Dim cbb As CommandBarButton
Call DeleteBar
Set cb = Application.CommandBars.Add(Name:="The Performance InsightT
Dashboard Controls", Position:=msoBarFloating, temporary:=True)
With cb
.Visible = True
Set cbb = .Controls.Add(Type:=msoControlButton)
With cbb
.Caption = "Refresh Data"
.Style = msoButtonIconAndCaption
.Caption = "Refresh Data"
.FaceId = 159
.OnAction = "InitializeDataInput2"
End With
Set cbb = .Controls.Add(Type:=msoControlButton)
With cbb
.Style = msoButtonIconAndCaption
.Caption = "Generate Reports"
.FaceId = 433
.OnAction = "ShowCommandPopupGenerateReports"
End With
End With
End Sub
My code last time was sloppy regarding the With's, but here I think it's
okay. So in the lines:
Set cbb = .Controls.Add(Type:=msoControlButton)
the ".Controls" is the same as "cb.Controls" but the "cb" doesn't need to be
specified because of the "With cb" above it.
In the lines:
With cbb
.Caption = "Refresh Data", etc,
".Caption" is the same as "cbb.Caption"
With/End With saves some resources, especially in some situations, becuase
you are only referring to the object once.
Looking ahead, you can see that using the same "cbb" variable multiple times
to refer to the most recently added control is like a loop. And a loop is
just what you want for more complex menus. What many people do for complex
menus is a table driven loop, like here:
http://spreadsheetpage.com/index.php/file/menu_maker/
Have fun!
Doug