PDA

View Full Version : Solved: Floating Toolbars



coliervile
03-22-2008, 04:24 AM
Good morning to everyone...depending on where you are. I'm using "lucas" (thank you) floating toolbar on the KB (http://vbaexpress.com/kb/getarticle.php?kb_id=921). My question is...can you have more than one floating toolbar displayed simultaneously? My reason for asking is that I want different toolbars to perform different functions on the same worksheet. I'm making an interactive baseball scorecard and I want different toolbars for; how runners get on base; how batters make out; and ways runners advance, etc. I would also like to set the color for each toolbar to help the user to differentiate between the toolbars. This is an example of what I have for the toolbar for How Runners Get on Base; Any suggestions are also appreciated.

Sub AddNewToolBar()
' This procedure creates a new temporary toolbar.
Dim ComBar As CommandBar, ComBarContrl As CommandBarControl
On Error GoTo ErrorHandler
' Create a new floating toolbar and make it visible.
On Error Resume Next
'Delete the toolbar if it already exists
CommandBars("Baseball Scorecard Toolbar").Delete
Set ComBar = CommandBars.Add(Name:="How Runners Get on Base", Position:= _
msoBarFloating, Temporary:=True)
ComBar.Visible = True
' Create a button with text on the bar and set some properties.
Set ComBarC With ComBarContrl
.Caption = "Single"
. .TooltipText = "Run Single"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "Double"
. .TooltipText = "Run Double"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "Triple"
. .TooltipText = "Run Triple"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "HR"
. .TooltipText = "Run Home Run"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "BB"
. .TooltipText = "Run BB"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "HBP"
. .TooltipText = "Run HBP"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "FC"
. .TooltipText = "Run Fielders Choice"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "GRD"
. .TooltipText = "Run Ground Rule Double"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "WP"
. .TooltipText = "Run Wild Pitch"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "PB"
. .TooltipText = "Run Pass Ball"
'the onaction line tells the button to run a certain marcro
.
End With
Set ComBarC With ComBarContrl
.Caption = "DI"
. .TooltipText = "Run Defenbive Interference"
'the onaction line tells the button to run a certain marcro
.
End With
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & vbCr & Err.Description
Exit Sub
End Sub

Bob Phillips
03-22-2008, 04:35 AM
Your code is not even close to working.

BUt why not just have one toolbar with different sections?

coliervile
03-22-2008, 04:56 AM
Hello Bob thanks for replying. For whatever reason the "onaction" part of the coding didn't copy, but the the coding does work. How do you go about sectioning in the same toolbar? In the scorecard there will be as many as 70 different buttons that the person keeping score can select from. You might be saying 70 buttons is this guy nuts that's a lot. But if you've ever kept score by hand at a baseball game there's that many choices for a person keeping score and then some. Once you play around with the buttons it's really pretty easy that's why I thought of color coding each toolbar might make it even easier. It's for the diehard score keepers.


Sub AddNewToolBar()
' This procedure creates a new temporary toolbar.
Dim ComBar As CommandBar, ComBarContrl As CommandBarControl
On Error GoTo ErrorHandler
' Create a new floating toolbar and make it visible.
On Error Resume Next
'Delete the toolbar if it already exists
CommandBars("Baseball Scorecard Toolbar").Delete
Set ComBar = CommandBars.Add(Name:="Baseball Scorecard Toolbar", Position:= _
msoBarFloating, Temporary:=True)
ComBar.Visible = True
' Create a button with text on the bar and set some properties.

Set ComBarC With ComBarContrl
.Caption = "Single"

. .TooltipText = "Run Single"
.
End With

Set ComBarC With ComBarContrl
.Caption = "Double"

. .TooltipText = "Run Double"
.
End With

Set ComBarC With ComBarContrl
.Caption = "Triple"

. .TooltipText = "Run Triple"
.
End With

Set ComBarC With ComBarContrl
.Caption = "HR"

. .TooltipText = "Run Home Run"
.
End With

Set ComBarC With ComBarContrl
.Caption = "BB"

. .TooltipText = "Run BB"
.
End With

Set ComBarC With ComBarContrl
.Caption = "HBP"

. .TooltipText = "Run HBP"
.
End With

Set ComBarC With ComBarContrl
.Caption = "FC"

. .TooltipText = "Run Fielders Choice"
.
End With

Set ComBarC With ComBarContrl
.Caption = "GRD"

. .TooltipText = "Run Ground Rule Double"
.
End With

Set ComBarC With ComBarContrl
.Caption = "WP"

. .TooltipText = "Run Wild Pitch"
.
End With

Set ComBarC With ComBarContrl
.Caption = "PB"

. .TooltipText = "Run Pass Ball"
.
End With

Set ComBarC With ComBarContrl
.Caption = "DI"

. .TooltipText = "Run Defenbive Interference"
.
End With
Exit Sub
ErrorHandler:
MsgBox "Error " & Err.Number & vbCr & Err.Description
Exit Sub
End Sub

coliervile
03-22-2008, 05:02 AM
That's really bizarre the VBA coding that i downloaded didn't showpu correctly. I copied my code over into the Message Box properly, but when it copies over into the thread is not even close to what I put in there????

Bob Phillips
03-22-2008, 05:05 AM
70 buttons is a lot, regardless of whether you have them on one toolbar or on many.

Is there any way that you can determine which toolbar is relevant at any one time?

coliervile
03-22-2008, 05:13 AM
There's not any one toolbar more relevant than the other. They are are going to be used equally. One is for the how the batter does or doesn't get on base, another for how the runners on base make outs, one for the runners on base and how they advance, and another for how the fielders make outs or errors. Are you a baseball fan Bob?

Bob Phillips
03-22-2008, 05:21 AM
No I'm not a baseball fan, I'm a sports fan :whistle:

By relevant, I don't mean how often they would get used, but when they would get used. For instance, is there any way that you could identify that when a user is in this cell, toolbar A should be available, in another cell tollbar VB should be available?

Bob Phillips
03-22-2008, 05:23 AM
Post a workbook with some toolbars Charlie top work with.

coliervile
03-22-2008, 05:54 AM
Here's a small sample of the scorecard. Open the workbook and activate the macro "AddNewToolBar" through Tools-Macro, the toolbar will activate with one button on it "Single", click on cell "D4" on worksheet2, click on the toolbar button "Single". This should give you an idea of what takes place on the scorecard.

coliervile
03-22-2008, 05:55 AM
Here's the workbook...

Bob Phillips
03-22-2008, 07:28 AM
That isn't exactly doing anything for me I am afraid. I don't understand what is happening, or why, nor do I really care.

I was hoping to see two or three of your toolbars. And what about the questions that I answered in #7?