Visual Basic Programming Code Examples Visual Basic > ActiveX Controls Code Examples Highlight all text in textbox Highlight all text in textbox 'Here is the main function that controls 'the highlighting of all text in a textbox. 'Additional commands can be added to this function 'to perform any other functions during a gotfocus 'event. Public Function txtGotFocus() Dim obj Set obj = Form1.ActiveControl If TypeOf obj is TextBox Then obj.SelStart = 0 obj.SelLength = Len(obj.Text) End if End Function 'Here is an example of how to reference the 'function in a textbox GotFocus() event. Private Sub Text1_GotFocus() txtGotFocus End Sub