Placeholder text on user form

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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,224,828
Messages
6,181,204
Members
453,022
Latest member
RobertV1609

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