Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textbox Text Disappear on Text Entry

Tags:

excel

vba

Basically I have a Userform that I have created, and I was wondering if it was possible to add Grey text that is there when the Userform loads but that disappears as soon as the user start to input text into the TextBox:

[image expired]

Once the user starts typing in the font color should change to black.

Any help would be appreciated.

like image 410
CaptainABC Avatar asked Jan 22 '26 22:01

CaptainABC


1 Answers

Something Like this?

Private Sub UserForm_Initialize()
    TextBox1.ForeColor = &HC0C0C0 '<~~ Grey Color
    TextBox1.Text = "Please Enter Name Here"
    CommandButton1.SetFocus '<~~ This is required so that the focus moves from TB
End Sub

Private Sub TextBox1_Enter()
    With TextBox1
        If .Text = "Please Enter Name Here" Then
            .ForeColor = &H80000008 '<~~ Black Color
            .Text = ""
        End If
    End With
End Sub

Private Sub TextBox1_AfterUpdate()
    With TextBox1
        If .Text = "" Then
            .ForeColor = &HC0C0C0
            .Text = "Please Enter Name Here"
        End If
    End With
End Sub

ScreenShot (In action)

enter image description here

like image 112
Siddharth Rout Avatar answered Jan 25 '26 15:01

Siddharth Rout