Change button label in Ribbon using VBA
I have a custom 开发者_开发百科Tab I have created. How can I use VBA to change the attributes of the controls on the tab. For example, I would like to change the label of a button with id="menubutton" depending on user seelctions in the program. It seems to me that it should be easy but I am struggling with this. Any help would be greatly appreciated.
You can try getLabel function with XML you can change your button label like this
<button id="customButton" getLabel="getLabel1" size="large" onAction="Example_Macro" />
With VBA you can use this macro to change label
Sub getLabel1(control As IRibbonControl, ByRef returnedVal)
returnedVal = "Hello"
End Sub
returnedVal will be your label for button.
Can you do this yourself (eg with the mouse and keyboard) in Word via the customise toolbars context menus?
- If so then switch on the macro recorder.
- Perform the action (eg use the keyboard and mouse to change the attributes you wish to ).
- Stop the macro recorder.
- Open up the VBA studio in Word and take a look at the macro that has been created, that should give you a good indication of what you need to do.
精彩评论