Manipulate Textbox Format When User Clicks On It

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I use this code below to manipulate the formatting of one of the textboxes in my userform.
I think it is doing what I want it to (sets default text and highlights it in preparation of being overwritten by the user). It appears to be working only when the user tabs to that textbox.
Is there a way to do this when the user click in that particular textbox?

Code:
Private Sub p_email_Enter()
    'Stop
    With s_email
        .Text = "@email"
        .ForeColor = RGB(227, 227, 227)
        .Font.Italic = True
        .SetFocus
        .SelStart = 0
        .SelLength = Len(.Text)
    End With
End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
In the code above did you make a typo (s_email vs p_email) by any chance?
 
Upvote 0
Yes. I did. I caught that once I tested further.
 
Upvote 0
OK. Anyway, make a dummy Text Box on your UserForm (a very tiny one) and hide that dummy behind the email Text Box (Z-order).
Than use this code for the Text Box itself
VBA Code:
Private Sub s_email_Enter()
    With .s_email
        .Text = "@email"
        .ForeColor = RGB(227, 227, 227)
        .Font.Italic = True
        .SelStart = 0
        .SelLength = Len(.Text)
        .SetFocus
    End With
End Sub

Private Sub s_email_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
   TbxDUMMY.SetFocus
   s_email.SetFocus
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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