How to make pale text inside the TextBox before selecting the TextBox

mmn1000

Board Regular
Joined
Mar 17, 2020
Messages
77
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hello

How can I make watermark textbox on my textbox?

For example, have you seen that in some TextBoxes, there is a faint writing, when you select it, the writing goes "Delete" and you can type.

I want to see if it is possible to do this in VBA Excel
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hello. Add to userform code:
VBA Code:
Private Sub TextBox1_Enter()
    If TextBox1.Value = "Delete" Then
        TextBox1.Value = ""
        TextBox1.ForeColor = &H80000008
    End If
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox1.Value = "" Then
        TextBox1.Value = "Delete"
        TextBox1.ForeColor = &H8000000C
    End If
End Sub

Private Sub UserForm_Activate()
    TextBox1.Value = "Delete"
    TextBox1.ForeColor = &H8000000C
    TextBox2.SetFocus '<== if you have a second textbox - use this line, if not - set focus to something else (ComboBox / CommandButton etc.)
    TextBox1.SetFocus
End Sub
 
Upvote 0
Solution
Hello. Add to userform code:
VBA Code:
Private Sub TextBox1_Enter()
    If TextBox1.Value = "Delete" Then
        TextBox1.Value = ""
        TextBox1.ForeColor = &H80000008
    End If
End Sub

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If TextBox1.Value = "" Then
        TextBox1.Value = "Delete"
        TextBox1.ForeColor = &H8000000C
    End If
End Sub

Private Sub UserForm_Activate()
    TextBox1.Value = "Delete"
    TextBox1.ForeColor = &H8000000C
    TextBox2.SetFocus '<== if you have a second textbox - use this line, if not - set focus to something else (ComboBox / CommandButton etc.)
    TextBox1.SetFocus
End Sub
Thank you for your beautiful code
 
Upvote 0

Forum statistics

Threads
1,216,059
Messages
6,128,542
Members
449,457
Latest member
ncguzzo

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