Ting Fung Li
Ting Fung Li

Reputation: 46

Change font and font size during creating userform programatically

I am going to create a userform programmatically, I am able to create other controls like commandbuttons, textboxes, optionbuttons...etc., as my wish.

But I can not figure out the way to set the font and font size at the beginning of creating the userform programmatically.

As there are near hundred controls, it would be better for me to set the font at the beginning, otherwise, I may set the font manually afterwards.

I tried the following for setting:

    Dim NewForm As Object

    Application.VBE.MainWindow.Visible = True

    Set NewForm = ThisWorkbook.VBProject.VBComponents.Add(vbext_ct_MSForm)
    With NewForm
        .Properties("Caption") = ""
        .Properties("Width") = 400
        .Properties("Height") = 400
------> 'Properties("Font.Name") = "Arial"
        'Properties("Font.size") = 9
               'Or
------> '.Font = "Arial"
        '.font.size = 9
        .Name = "frmWebScraping"
    End With

    'code for creating other controls with no problem is neglected

End Sub

Upvotes: 2

Views: 3186

Answers (1)

Pᴇʜ
Pᴇʜ

Reputation: 57743

The correct properties are:

.Properties("Font").Value.Item("Name") = "Arial"
.Properties("Font").Value.Item("Size") = 9

enter image description here

Upvotes: 2

Related Questions