Placeholder text on user form

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
On my userform how can we use placeholder text,

I dont wish to use a label above a textbox so have some faint text in the textbox of which disappears when the textbox becomes active etc & starts to write
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Assuming that your textbox is called TextBox1, maybe something like this...

VBA Code:
Option Explicit

Const PLACEHOLDER_TEXT As String = "Enter text here"
Const PLACEHOLDRR_FONT_COLOR As String = &HC0C0C0 'light grey

Dim originalFontColor As Long

Private Sub TextBox1_Enter()

    With Me.TextBox1
        If .Value = PLACEHOLDER_TEXT Then
            .Value = ""
            .ForeColor = originalFontColor
        End If
    End With
    
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

    With Me.TextBox1
        If Len(.Value) = 0 Then
            .ForeColor = PLACEHOLDRR_FONT_COLOR
            .Value = PLACEHOLDER_TEXT
        End If
    End With

End Sub

Private Sub UserForm_Initialize()

    originalFontColor = Me.TextBox1.ForeColor

    With Me.TextBox1
        .ForeColor = PLACEHOLDRR_FONT_COLOR
        .Value = PLACEHOLDER_TEXT
    End With
    
End Sub

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top