简体   繁体   中英

VBA Make a text box in a UserForm Active when the UserForm activates?

如何在激活用户窗体时激活用户窗体中的文本框,以便用户无需单击文本框即可开始输入?

What you are looking for is the TabIndex Property.

Every object on your userform has one, it is the order to which object on the userform are selected when you press the tab button. The object with 0 TabIndex will be the active object when a form is loaded also:

So with the textbox selected go to the properties pane and look for Tabindex set this to 0 and your textbox will be selected on open.

在此处输入图片说明

You can also set other textboxes index to 1,2,3 and on, so that if the form is being filled out you can simply press tab to go from one text box to another.

Use .SetFocus . If your textbox's name is TextBox1 , the following works:

Private Sub UserForm_Initialize()
    TextBox1.SetFocus
End Sub

Let us know if this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM