+ Reply to Thread
Results 1 to 7 of 7

Display Full Text within Textbox (On A UserForm) when you hover over the textbox

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Display Full Text within Textbox (On A UserForm) when you hover over the textbox

    Hi all,

    Is there any way to hover over a textbox on a userform and for it to display the full text within the textbox, a bit like it appears when you put a tip on a Active X control.

    At the moment it is diffulcult to see the potential full amount in a textbox because of its size. The size of the texbox can't be altered.

    Thanks in advance for your help!

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Display Full Text within Textbox (On A UserForm) when you hover over the textbox

    You could put this in the Userform code module
    Private Sub TextBox1_Change()
        TextBox1.ControlTipText = TextBox1.Text
    End Sub
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Re: Display Full Text within Textbox (On A UserForm) when you hover over the textbox

    That's is so simple... Thanks for that. I was doing something similar but didn't even think of the controltip feature being used like that.

    On a side note, do you know how to word-wrap the tip. At the moment it just displays in long line?

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Display Full Text within Textbox (On A UserForm) when you hover over the textbox

    No, I don't know how to wrap the control tip. Even inserting a vbCrLf doesn't make it more than one line.

  5. #5
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Re: Display Full Text within Textbox (On A UserForm) when you hover over the textbox

    Cheers for the reply... I might have to think of a work around!

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Display Full Text within Textbox (On A UserForm) when you hover over the textbox

    I might try a Lable whose visibility is controlled by the TextBox's MouseMove event.
    Create a Class module named clsHoverLabel with this code in it.
    ' in clsHoverLabel
    
    Public WithEvents myTextBox As MSForms.TextBox
    Public WithEvents myLabel As MSForms.Label
    Dim ShowMe As Boolean
    
    Private Function CreateLabel() As MSForms.Label
        Set CreateLabel = myTextBox.Parent.Controls.Add("forms.Label.1")
        With CreateLabel
            .AutoSize = False
            .BackColor = vbYellow
            .BackStyle = fmBackStyleOpaque
            .BorderStyle = fmBorderStyleSingle
            .Width = myTextBox.Width
            .Visible = False
            .Caption = myTextBox.Text
            .AutoSize = True
            .Top = myTextBox.Top + myTextBox.Height + 5
            .Left = myTextBox.Left + 10
        End With
        Set myLabel = CreateLabel
    End Function
    
    Property Set TextBox(inBox As MSForms.TextBox)
        Set myTextBox = inBox
        CreateLabel
    End Property
    
    Property Get Visible() As Boolean
        Visible = myLabel.Visible
    End Property
    Property Let Visible(inVal As Boolean)
        myLabel.Visible = inVal And (Len(myTextBox.Text) > 0)
    End Property
    
    Private Sub myLabel_Click()
        myLabel.Visible = False
    End Sub
    
    Private Sub myTextBox_Change()
        With myLabel
            .AutoSize = False
            .Caption = myTextBox.Text
            .Width = myTextBox.Width * 2
            .AutoSize = True
            .AutoSize = False
            .Width = WorksheetFunction.Max(.Width, myTextBox.Width)
            .Visible = (Len(myTextBox.Text) > 0) And Me.Visible
        End With
    End Sub
    
    Private Sub myTextBox_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
        With myTextBox
            If X < 2 Or Y < 2 Or (.Width - X) < 2 Or (.Height - Y) < 2 Then
                Me.Visible = False
            Else
                Me.Visible = True
            End If
        End With
    End Sub
    Then put code like this in the userform's code module
    Dim LabeledTextbox As clsHoverLabel
    
    Private Sub UserForm_Initialize()
        Set LabeledTextbox = New clsHoverLabel
        Set LabeledTextbox.TextBox = TextBox1
    End Sub

  7. #7
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Re: Display Full Text within Textbox (On A UserForm) when you hover over the textbox

    Hi, thanks for this. I'll have a play tonight and see if it works. Thanks for your help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. copy text from userform textbox to sheet textbox
    By Dfrost in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-28-2015, 02:19 AM
  2. [SOLVED] Excel 2010 - Userform - display date from textbox in a label or textbox in 'ddd' format
    By theshybutterfly in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2015, 10:54 PM
  3. Excel 2010 – VBA Userforms – Vlookup via Textbox, display result in another textbox
    By theshybutterfly in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-29-2015, 12:31 AM
  4. Replies: 23
    Last Post: 07-12-2014, 07:09 PM
  5. Replies: 2
    Last Post: 01-05-2013, 12:42 AM
  6. Printing word document from full file path in textbox in userform
    By pharmsunil2010 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-14-2010, 05:37 AM
  7. Display hyperlink text in userform textbox
    By tapapad in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2008, 06:37 PM

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