Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511

    Question Unanswered: Set focus to worksheet textbox

    Is it possible to set focus to an Excel 2003 worksheet text box? I tried this in the event handler code for a
    check box and it produces the error message "Object doesn't support this property or method.
    Code:
    With Me.txtMyTextBox
                .SetFocus
     End With

  2. #2
    Join Date
    Jan 2002
    Location
    Bay Area
    Posts
    511
    I was not able to find a VBA one-line-of-code solution to cause an Excel 2003
    worksheet text box to take the focus.

    A combination of steps produces the effect I was looking for, which include
    activating the text box and causing its value to be temporarily changed to a
    unique value, plus setting the SelStart property. A sample file is attached.

    Code:
    Private Sub CheckBox1_Click()
    Dim tmp As String
    
        If CheckBox1.Value Then     'text box to take focus
            TextBox1.Activate
            tmp = TextBox1.Text
            TextBox1.Text = Now()
            TextBox1.Text = tmp
            TextBox1.SelStart = Len(TextBox1.Text)
        Else
            Cells(Selection.Row, Selection.Column).Select
        End If
    
    End Sub
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •