VBA textbox

Hiport

Active Member
Joined
May 9, 2008
Messages
455
what is the code to make text box active in VBA

Private Sub TextBox1_Change()

??????

End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If you mean Textbox as a control on worksheet then:

Code:
'Assuming Sheet1 is the worksheet
Sheet1.TextBox1.Activate

If you mean Textbox control on a userform then:

Code:
'Assuming Userform1 is the userform
Userform1.TextBox1.SetFocus

Note: I don't think that you would actually need to use this code in Change event as in your question but somewhere else since the active control will be already itself when Change event is occuring.
 
Last edited:
Upvote 0
i get complie error with the first piece of code, method or data member not found

If you mean Textbox as a control on worksheet then:

Code:
'Assuming Sheet1 is the worksheet
Sheet1.TextBox1.Activate

If you mean Textbox control on a userform then:

Code:
'Assuming Userform1 is the userform
Userform1.TextBox1.SetFocus

Note: I don't think that you would actually need to use this code in Change event as in your question but somewhere else since the active control will be already itself when Change event is occuring.
 
Upvote 0
Hiport

You really need to tell us where this textbox is located.
 
Upvote 0
  • Please make sure your sheet object name is Sheet1 or better use Activesheet instead Sheet1 object name
Code:
Activesheet.TextBox1.Activate
  • Also make sure your text box name is Textbox1 (or change the code accordingly)
You can copy and paste following code line in debug window in VBE (Ctrl+G) to make sure about the object names on the active sheet:

Code:
for each obj in activesheet.OLEObjects :debug.Print obj.name:next
 
Upvote 0

Forum statistics

Threads
1,214,599
Messages
6,120,449
Members
448,966
Latest member
DannyC96

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