Cant setfocus on a control

eduzs

Well-known Member
Joined
Jul 6, 2014
Messages
701
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
I have a textbox

userform1.show
userform1.textbox1.setfocus

But it not work.

Want to start to type text without needing to click on the control to enter in the field.

Thanks
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try this in your Userform code Module
Code:
Private Sub UserForm_Initialize()
Me.TextBox1.SetFocus
End Sub
 
Upvote 0
Sorry, can't use this because is not whem initialize, I hide the useform, show a messagebox and then show userform1 and go inside textobox field to start typing.

I supose that there's another way to go to a fiel, using something with enterfieldbehavior.
 
Upvote 0
You could set the textbox1 TabIndex Property to 0 as follows:
Code:
Sub Test()
    UserForm1.TextBox1.TabIndex = 0
    UserForm1.Show
End Sub

Or, if you don't want to disturb the TabIndexes order of the userform controls you can use the follwing:

Code:
Sub Test()
    Application.OnTime Now, "SetFocus"
    UserForm1.Show
End Sub

Sub SetFocus()
    UserForm1.TextBox1.SetFocus
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,241
Messages
6,054,320
Members
444,717
Latest member
melindanegron

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top