Share via

Changing the font properties of a Check Box (Control Form) in Excel 2007

Anonymous
2014-03-26T20:24:51+00:00

Hello,

I've been browsing around for an answer to this for quite some time, but I cannot seem to find what I'm looking for.

Under the "Developer" tab, in "Controls" on the ribbon, there is an "Insert" dropdown. In that dropdown, you can insert a "Check Box (Form Controls)." This allowed me to have multiple checkboxes in my spreadsheet. However, the font type and face that they come in is generic, and seemingly cannot be changed.

I right clicked on the object and looked in "Format Control" and there is nothing that would help me there. I also cannot use the normal font tools on the home ribbon either. My only guess is that what I need to do is edit the object in VBA itself. When I go in, here is the code that I see:

Sub CheckBox10_Click()

End Sub

It's pretty simple and straightforward. What I'm wondering is if there is anything I can edit in the VBA that would at least allow me to make the font a little larger than what looks to be 10 point font. Any help would be greatly appreciated.

Thank you in advance.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. OssieMac 48,001 Reputation points Volunteer Moderator
    2014-03-29T12:04:13+00:00

    Hello Peter,

    AFAIK you cannot set the fonts for the Forms control Checkbox. The easiest way around this is to use the ActiveX controls. After creating ActiveX controls, Right click the control and select Properties. When an ActiveX control is created, the Design Mode defaults to On (when it is surrounded by Orange color.) Turn off design mode when finished setting properties etc. If you need to come back to the control to change properties then click the Design Mode icon first and then select the control.

    Having said that, a more complex method is to superimpose a textbox over the Forms Control Checkbox and you can control the font format within the TextBox. The following code creates a Checkbox and superimposes a TextBox and formats the Font in the TextBox.

    I have included a simple sub at the bottom that you might find handy to delete the checkboxes and textboxes during testing.

    I suggest that you copy the code into a blank workbook and run it. The Checkbox is created at the active cell. If you can follow the code and adapt it to your use then well and good but in my opinion it is much more difficult than simply using ActiveX controls.

    Sub CreateFormsCheckBoxes()

        Dim objCtrl As Object

        Dim dblLeft As Double

        Dim dblTop As Double

        Dim dblWidth As Double

        Dim dblHeight As Double

        Dim shp As Shape

        Dim strCaption As String

        Dim lngCapLen As Long

        strCaption = "My Check Box" 'Edit to required caption for checkbox.

        lngCapLen = Len(strCaption)

        With Sheets("Sheet1")

            With ActiveCell

                'Position and size with respect to the cell location

                'Size and position adjusted slightly to prevent grid lines being covered

                dblLeft = .Left + 1

                dblWidth = .Width * 3 - 2

                dblHeight = .Height - 2

                dblTop = .Top + 1

            End With

            Set objCtrl = .CheckBoxes.Add(dblLeft, dblTop, dblWidth, dblHeight)

            objCtrl.Name = "chkBox1"

            objCtrl.Characters.Text = ""    'No name within the CheckBox

            'Superimpose a TextBox over the CheckBox

            dblLeft = dblLeft + 15      'Move left of TextBox to right so Check is visible

            dblWidth = dblWidth - 15    'Shorten width of TextBox to align right side of CheckBox

            Set shp = .Shapes.AddTextbox(msoTextOrientationHorizontal, dblLeft, dblTop, dblWidth, dblHeight)

        End With

        shp.TextFrame2.TextRange.Characters.Text = strCaption       'Insert the caption

        shp.TextFrame2.VerticalAnchor = msoAnchorMiddle     'Centre font top to bottom

        shp.Line.Visible = msoFalse              'No visible border

        With shp.TextFrame2.TextRange.Characters(1, lngCapLen).Font

            .NameComplexScript = "Times New Roman"

            .Size = 12

            .Bold = msoTrue

            .Fill.Visible = msoTrue

            .Fill.ForeColor.RGB = RGB(255, 0, 0)

            '**************************************************************

            'The following are in regard to the Font; not the shape fill.

            'All untested.

            'If shape is right clicked on the worksheet

            'and the Drawing Tools ribbon that appears is selected

            'then see the Word Art Styes block to which these apply to.

            '.Fill.ForeColor.ObjectThemeColor = msoThemeColorDark1

            '.Fill.ForeColor.TintAndShade = 0

            '.Fill.ForeColor.Brightness = 0

            '.Fill.Transparency = 0

            '.Fill.Solid

            '***************************************************************

        End With

        ActiveCell.Offset(2, 0).Select  'Move selection away from shapes

    End Sub

    Sub ClearShapes()

    'Use this sub to delete all of the CheckBoxes and TextBoxes during testing.

    Dim shp As Shape

    For Each shp In ActiveSheet.Shapes

        shp.Delete

    Next shp

    End Sub

    3 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2014-04-02T18:17:58+00:00

    Thank you so much for this response. Hands down one of the best and most detailed responses I have ever gotten. Thank you!

    I actually was tinkering around after I posted this (as I like to not just leave it up to fate to find my answer) and did notice the editable properties of ActiveX forms, so I ended up changing them all over to ActiveX instead. This code is definitely helpful though should I ever choose to take a more customized approach to everything.

    Thank you again so much!

    0 comments No comments