Share via

Building UserForms With VBA Purely Through Code

Anonymous
2021-08-19T17:16:01+00:00

Hi,

Via keyboard, the Excel editor does not allow keyboard-only users to get form controls from the toolbox onto a form. Is there a work-around to solve this? Failing that, can anyone point me to sample code for laying out controls on my form, and, hopefully, UI guidelines, so I can build some generic routines I can reuse to do this? I'm asking this for accessibility reasons.

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

1 answer

Sort by: Most helpful
  1. HansV 462.6K Reputation points
    2021-08-19T18:29:08+00:00

    Here is a starting point. It assumes that UserForm1 has already been created.

    Sub CreateControls()
    Dim ctl As MSForms.Control
    With UserForm1
    .Caption = "My Form"
    With .Controls.Add(bstrProgID:="Forms.Label.1", Name:="Label1", Visible:=True)
    .Left = 12
    .Top = 12
    .Width = 96
    .Height = 18
    .Caption = "My Label"
    End With
    With .Controls.Add(bstrProgID:="Forms.TextBox.1", Name:="TextBox1", Visible:=True)
    .Left = 120
    .Top = 12
    .Width = 96
    .Height = 18
    .Text = "Some Text"
    End With
    .Show
    End With
    End Sub

    Was this answer helpful?

    4 people found this answer helpful.
    0 comments No comments