文本框文本消失文本输入Excel VBA [英] Textbox Text Disappear on Text Entry Excel VBA

查看:919
本文介绍了文本框文本消失文本输入Excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我已经创建了一个Userform,我想知道是否可以在Userform加载时添加格式文本,但是一旦用户开始将文本输入到TextBox中,就会消失: p>

Userform http://im34.gulfup.com/ rDwF8.png



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



解决方案

这样的东西

  Private Sub UserForm_Initialize()
TextBox1.ForeColor =& HC0C0C0'< ~~灰色
TextBox1.Text =请在此输入名称
CommandButton1.SetFocus'< ~~这是必需的,以便焦点从TB移动
End Sub

Private Sub TextBox1_Enter()
With TextBox1
If。 Text =请在此输入名称然后
.ForeColor =& H 80000008'< ~~黑色
.Text =
如果
结束
结束Sub

私有Sub TextBox1_AfterUpdate()
与TextBox1
如果.Text =然后
.ForeColor =& HC0C0C0
.Text =请在此输入名称
结束如果
结束与
End Sub

ScreenShot(In action)




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:

Userform http://im34.gulfup.com/rDwF8.png

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

Any help would be appreciated.

解决方案

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)

这篇关于文本框文本消失文本输入Excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆