example code for

C

Charlie

Would someone have some example code for renaming a button on a custom
toolbar called "schedule"?
 
J

Jean-Guy Marcil

Charlie was telling us:
Charlie nous racontait que :
Would someone have some example code for renaming a button on a custom
toolbar called "schedule"?

With CommandBars("schedule")
.Controls("OldCaption").Caption = "NewCaption"
End With


--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Helmut Weber

Hi Jean-Guy,

would you be so kind to shed a bit more light on this.

In the customize dialog there is no caption.property,
only "name".

In the object-browser for commandbarcontrol
there is no "name" property, only caption.

I got a button, which displays "test90a",
if the mouse pointer rests on that button.

With CommandBars("Test")
.Controls("test90a").Caption = "test90b"
End With

results in error 5: "invalid procedure call or argument"

The name of the button, as I get it from the
customize-dialog is "xxx".

With CommandBars("Test")
.Controls("xxx").Caption = "test90b"
End With

changes the name (!) of the button,
as displayed in the customize-dialog,
but not what is displayed,
if the mouse pointer rests on that button.

With CommandBars("Test")
MsgBox .Controls("xxx").Caption
End With

returns: "test90a"

I am confused.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
J

Jean-Guy Marcil

Helmut Weber was telling us:
Helmut Weber nous racontait que :
Hi Jean-Guy,

would you be so kind to shed a bit more light on this.

In the customize dialog there is no caption.property,
only "name".

In the object-browser for commandbarcontrol
there is no "name" property, only caption.

I got a button, which displays "test90a",
if the mouse pointer rests on that button.

With CommandBars("Test")
.Controls("test90a").Caption = "test90b"
End With

results in error 5: "invalid procedure call or argument"

The name of the button, as I get it from the
customize-dialog is "xxx".

With CommandBars("Test")
.Controls("xxx").Caption = "test90b"
End With

changes the name (!) of the button,
as displayed in the customize-dialog,
but not what is displayed,
if the mouse pointer rests on that button.

With CommandBars("Test")
MsgBox .Controls("xxx").Caption
End With

returns: "test90a"

I am confused.


Hi Helmut,

I am not sure what you mean by "mouse pointer rests on that button" and I am
not convinced it is relevant in this case.
The UI uses "Name", but in fact it is the .Caption property in the object
library.

I created a toolbar called "Test".
I added a new menu called "test90a"
(All of this through the "Customize" dialog)

Then I used the code you posted:
With CommandBars("Test")
.Controls("test90a").Caption = "test90b"
End With
and everything worked as expected.

Then, to make sure, I used
With CommandBars("Test")
.Controls("test90b").Caption = "MoreTest"
End With

and it worked again.

Then, I tried again, but this tine, instead of a "New menu" type of control,
I added an Autotext type of button and used
With CommandBars("Test")
.Controls("Greetings").Caption = "NewName"
End With

and everything again worked as expected.

I am not sure how you got "xxx" in the dialog, but "test90a" displayed on
the toolbar.
Never seen that behaviour before, whatever name you type under name is in
fact the .Caption property that ends up being displayed in the UI.

Finally, I did as I wrote above to create a toolbar with a new menu, but
this time I added a button under that menu, again an Autotext.
So, I now had a toolbar called "Test", a menu called "NewName" and under
that menu a button called "RE :".
Using
With CommandBars("Test").Controls("NewName").CommandBar
.Controls("RE :").Caption = "NewButtonName"
End With
I changed the name/caption of the button under the menu.
No errors...

So I am not sure how I can shed more light or help clarify your confusion...

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Helmut Weber

Hi Jean-Guy,

thanks a lot.
I hope, you didn't waste to much time on it.
I am not sure what you mean by "mouse pointer rests on that button"
and I am not convinced it is relevant in this case.

It's the TooltipText, as I've found out in the meantime.
And that's what is displayed,
if "default style" is checked in the customize dialog,
not the caption.
The UI uses "Name",
but in fact it is the .Caption property in the object library.

That was the main point I wanted to have to have clarified.

Still, for built-in buttons on built-in toolbars,
the tooltiptext displays the name (or caption).
Maybe unless tooltiptext it is changed explicitly.
Whereas for a custom button on a custom toolbar,
the tooltiptext doesn't change with a change of the caption (or name).

One lazy sunday afternoon I'll look more deeply into it.

Thanks again.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top