+ Reply to Thread
Results 1 to 2 of 2

highlighted text

  1. #1
    MD
    Guest

    highlighted text

    In the "Save as" box, the name of a workbook is pre-highlighted for you to
    change it. How do I do the same in a user form ?

    I have a form with a text box... say txtbox1, I also have set a default
    value of "0" in the txtbox1.
    I set focus on txtbox1 when form is shown but the zero is not hightlighted
    like I want...

    Any tips?




  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello MD,

    Copy and paste this code into a standard VBA Module.

    To add a Module to project:
    1) Press Alt + F11 in Excel to open the VB Editor
    2) Press Alt + I to activate the Insert menu
    3) Press M to add a Module

    Public Sub HighlightTextBox(TextBox_Name As String)

    'Highlight TextBox Text

    With UserForms(0).Controls(TextBox_Name)
    .SetFocus
    .SelStart = 0
    .SelLength = Len(.Text)
    End With

    End Sub


    Calling the Macro:
    Enclose the name of the TextBox whose text you want to highlight in quotes.

    HighlightTextBox "txtbox1"


    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1