ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   XL2003 VBA Add msoControlButton BUG or Feature? (https://www.excelbanter.com/excel-programming/308658-xl2003-vba-add-msocontrolbutton-bug-feature.html)

rormeister

XL2003 VBA Add msoControlButton BUG or Feature?
 
Using VBA I am trying to add a simple button to CommandBars(1). The
result of the code below is the button is created but the Caption is
missing. From the immediate window, the Caption Property contains the
value I assigned in the code, it just refuses to display on the
toolbar. This has worked for me hundreds of times in XL2k. Can you
help?

Sub AddUCXButton()
'
On Error Resume Next
DeleteUCXButton
Dim MenuObject
Set MenuObject = Application.CommandBars(1). _
Controls.Add(Befo=11, _
Type:=msoControlButton, Temporary:=True)

MenuObject.Caption = "&UCX830"
MenuObject.OnAction = "RunAMacro"
End Sub

TIA
Ror

Tom Ogilvy

XL2003 VBA Add msoControlButton BUG or Feature?
 
What is the style setting for the button? Does it include showing the
caption?

--
Regards,
Tom Ogilvy

"rormeister" wrote in message
m...
Using VBA I am trying to add a simple button to CommandBars(1). The
result of the code below is the button is created but the Caption is
missing. From the immediate window, the Caption Property contains the
value I assigned in the code, it just refuses to display on the
toolbar. This has worked for me hundreds of times in XL2k. Can you
help?

Sub AddUCXButton()
'
On Error Resume Next
DeleteUCXButton
Dim MenuObject
Set MenuObject = Application.CommandBars(1). _
Controls.Add(Befo=11, _
Type:=msoControlButton, Temporary:=True)

MenuObject.Caption = "&UCX830"
MenuObject.OnAction = "RunAMacro"
End Sub

TIA
Ror




rormeister

XL2003 VBA Add msoControlButton BUG or Feature?
 
Hi Tom,

Thanks for the reply. Yes, it seems that XL2003 requires the style
attribute to be set. XL2000 is more forgiving in that if you don't
specificly imply that the button is an msoButtonCaption, the fact you
set the caption value seems to be enough.

What is puzzling, the code without the Style works for workbooks that
were created in XL2000, but requires Style in new XL2003 worksheets.

Thanks again!

"Tom Ogilvy" wrote in message ...
What is the style setting for the button? Does it include showing the
caption?

--
Regards,
Tom Ogilvy

"rormeister" wrote in message
m...
Using VBA I am trying to add a simple button to CommandBars(1). The
result of the code below is the button is created but the Caption is
missing. From the immediate window, the Caption Property contains the
value I assigned in the code, it just refuses to display on the
toolbar. This has worked for me hundreds of times in XL2k. Can you
help?

Sub AddUCXButton()
'
On Error Resume Next
DeleteUCXButton
Dim MenuObject
Set MenuObject = Application.CommandBars(1). _
Controls.Add(Befo=11, _
Type:=msoControlButton, Temporary:=True)

MenuObject.Caption = "&UCX830"
MenuObject.OnAction = "RunAMacro"
End Sub

TIA
Ror



All times are GMT +1. The time now is 08:58 PM.

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