Custom display name (with spaces) for VBA macro button in ribbon

Custom display name (with spaces) for VBA macro button in ribbon

DRoam
Mentor Mentor
1,745 Views
2 Replies
Message 1 of 3

Custom display name (with spaces) for VBA macro button in ribbon

DRoam
Mentor
Mentor

Is there any way to add a button to the ribbon for a VBA macro, but be able to have spaces in the button's name?

 

I know how to add a macro to the ribbon using the CommandControls.AddMacro method. However, that method only takes MacroControlDefinitions as the control definition input, and MacroControlDefinitions are created using ControlDefinitions.AddMacroControlDefinition, which gives no provision for specifying a DisplayName. After creation, the DisplayName property is read-only and is locked to the macro's VBA sub name, which cannot have spaces in it.

 

I'm wondering if maybe it's possible to assign a VBA macro as the OnExecute event for a ButtonDefinition? If so, then we could create the macro's button definition using ControlDefinitions.AddButtonDefinition, which DOES allow you to set the DisplayName at creation.

 

Is this possible? Or is there any other way to set a custom display name for a VBA macro button?

Accepted solutions (1)
1,746 Views
2 Replies
Replies (2)
Message 2 of 3

DRoam
Mentor
Mentor
Accepted solution

Well cool! Just found a really simple way to add spaces to a macro name/button: Use a non-breaking space. I was 99% sure this wouldn't work, but it did.

 

To use spaces in a VBA macro's button, go to the Sub name and enter a non-breaking space wherever you want a space by holding down the Alt key, typing 0160 (using the number pad), and then release the Alt key. It should enter what looks like a normal space but is actually a non-breaking space.

 

You can also (and, in fact, will need to) add the same non-breaking spaces in any iLogic or VBA code that references the Sub, as well as in the file name for the BMP icon file for the macro.

 

Then go thru your ribbon customizations and remove the old macros, and replace them with the spaced ones.

 

My custom ribbon buttons now have nice-looking spaces between each word rather_than_ugly_underscores OrClutteredCamelCase.

Message 3 of 3

Jason.Rugg
Collaborator
Collaborator

@DRoam This worked well for me as well. Now my question is, how can I rename the panel name on the ribbon menu? By default mine is called "User Commands".

0 Likes