文本框Excel VBA上的文本框文本消失

Cap*_*ABC 3 excel vba excel-vba

基本上我有一个我创建的Userform,我想知道是否可以在Userform加载时添加Gray文本,但是一旦用户开始在TextBox中输入文本就会消失:

用户形式http://im34.gulfup.com/rDwF8.png

一旦用户开始输入字体颜色应该变为黑色.

任何帮助,将不胜感激.

Sid*_*out 9

像这样的东西?

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
Run Code Online (Sandbox Code Playgroud)

ScreenShot(在行动中)

在此输入图像描述