Search code examples
excelexcel-2013activexobjectvba

Setting font of an ActiveX commandbutton


I have an Excel spreadsheet, and I'm trying to set the font of an ActiveX commandbutton with this code:

With Worksheets("Schedule Tool").Shapes("CommandButton1")
    .Height = 31.4645669291
    .Width = 145.4173228346
    .Font = "Calibri"
    .Font.Size = 9
    .Left = 1017.75
    .Top = 130.5
End With

When it hits the .Font and .Font.Size bits, it breaks and says "Object doesn't support this property or method". I'm all right skipping .Font, but changing the size is critical.

I've tried googling it to find the correct properties for ActiveX commandbuttons (I assume I'm just using the wrong ones), but all I find is endless discussions of the old shrinking button glitch. Any advice?


Solution

  • You can use:

    With Worksheets("Schedule Tool").Shapes("CommandButton1")
        .Height = 31.4645669291
        .Width = 145.4173228346
        With .DrawingObject.Object.Font
            .Name = "Calibri"
            .Size = 9
        End With
        .Left = 1017.75
        .Top = 130.5
    End With