views:

1052

answers:

1

I'm trying to add a button to a new CommandBar (for the Add-in tab) with Excel VBA. I can get the button into the ribbon and can get an image to show up for it if I use a FaceId, but I can't get the Caption to appear. Is there some way to do this? Do i have to use an image instead?

With Application.CommandBars.Add("Open Forms")
    With .Controls.Add(msoControlButton)
        .OnAction = "ThisWorkbook.FunctionFunction"
        .Caption = "Call the Function"
    End With

    .Visible = True
End With
A: 

You need to set the style property of the new button as follows:

    .Style = msoButtonIconAndCaption

There are other options for the style(e.g. msoButtonCaption). You can easily see the list through intellisense.

atesalp