Results 1 to 6 of 6

VBA textbox

This is a discussion on VBA textbox within the Excel Questions forums, part of the Question Forums category; what is the code to make text box active in VBA Private Sub TextBox1_Change() ?????? End Sub...

  1. #1
    Board Regular
    Join Date
    May 2008
    Posts
    453

    Default VBA textbox

    what is the code to make text box active in VBA

    Private Sub TextBox1_Change()

    ??????

    End Sub

  2. #2
    BatCoder
    Join Date
    Feb 2002
    Location
    Turkey
    Posts
    764

    Default Re: VBA textbox

    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 by smozgur; Nov 26th, 2008 at 07:18 PM.

  3. #3
    Board Regular
    Join Date
    May 2008
    Posts
    453

    Default Re: VBA textbox

    i get complie error with the first piece of code, method or data member not found

    Quote Originally Posted by smozgur View Post
    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.

  4. #4
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling
    Posts
    66,168

    Default Re: VBA textbox

    Hiport

    You really need to tell us where this textbox is located.
    If posting code please use code tags.

  5. #5
    Board Regular
    Join Date
    May 2008
    Posts
    453

    Default Re: VBA textbox

    Quote Originally Posted by Norie View Post
    Hiport

    You really need to tell us where this textbox is located.

    Text box is located in Sheet 1

  6. #6
    BatCoder
    Join Date
    Feb 2002
    Location
    Turkey
    Posts
    764

    Default Re: VBA textbox

    • 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

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com