ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   caption property in command bar (excel 2003) (https://www.excelbanter.com/excel-programming/396588-caption-property-command-bar-excel-2003-a.html)

JillC

caption property in command bar (excel 2003)
 
I am trying to add a caption to a control button on a command bar using many
variations of the following code in the Workbook_Open event:
Set myBar = Application.CommandBars.Add(myName, msoBarTop, , True)
With myBar
.Controls.Add msoControlButton
.Controls(1).Caption = "useful info"
End With

The command bar shows no button, just blank space, if the mouse hovers over
the space the caption appears, but I want the caption to appear on a button
that a user can press. I can attach the correct macro to the 'space' and
works if i click the 'space'.

Where am I going wrong?
--
Thanks in advance, Jill C

papou[_2_]

caption property in command bar (excel 2003)
 
Hello Jill
Set myBar = Application.CommandBars.Add(myName, msoBarTop, , True)
set Myctr = myBar.Controls.Add msoControlButton
Myctr.Caption = "useful info"

HTH
Cordially
Pascal

"jillc" a écrit dans le message de news:
...
I am trying to add a caption to a control button on a command bar using
many
variations of the following code in the Workbook_Open event:
Set myBar = Application.CommandBars.Add(myName, msoBarTop, , True)
With myBar
.Controls.Add msoControlButton
.Controls(1).Caption = "useful info"
End With

The command bar shows no button, just blank space, if the mouse hovers
over
the space the caption appears, but I want the caption to appear on a
button
that a user can press. I can attach the correct macro to the 'space' and
works if i click the 'space'.

Where am I going wrong?
--
Thanks in advance, Jill C




Halim

caption property in command bar (excel 2003)
 
hi,

I've modify your code:
Dim mybar As CommandBar, Myname
Dim btn As CommandBarButton

Myname = "Test"
Set mybar = Application.CommandBars.Add(Myname, msoBarTop, , True)
Set btn = mybar.Controls.Add(msoControlButton)
With btn
.Caption = "useful info"
.Style = msoButtonCaption
End With
mybar.Visible = True

<smile
--
Regards,

Halim



"jillc" wrote:

I am trying to add a caption to a control button on a command bar using many
variations of the following code in the Workbook_Open event:
Set myBar = Application.CommandBars.Add(myName, msoBarTop, , True)
With myBar
.Controls.Add msoControlButton
.Controls(1).Caption = "useful info"
End With

The command bar shows no button, just blank space, if the mouse hovers over
the space the caption appears, but I want the caption to appear on a button
that a user can press. I can attach the correct macro to the 'space' and
works if i click the 'space'.

Where am I going wrong?
--
Thanks in advance, Jill C



All times are GMT +1. The time now is 05:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com