"Greying" a UserForm text input box

  • Thread starter Thread starter den1s
  • Start date Start date
D

den1s

Hi,

Hi,

Is there a way to "grey" out a text input box in VBA Excel and thus
prevent users from inputing text, until certain conditions are
fulfullied?

I am creating a UserForm and I would like to grey out the text input
box when a CheckBox is clicked. Not sure exactly how to do it though.
 
den1s,

Private Sub CheckBox1_Click()
With Me.TextBox1
.Enabled = Me.CheckBox1.Value
End With
End Sub

You can also used the Locked property of the Textbox. It has 2 advantages.
When you change the backcolor to "gray" the text stays black so it can be
read, and the user can copy the text for pasting elsewhere. Something to
play with at least:

Private Sub CheckBox1_Click()
With Me.TextBox1
.Locked = Not Me.CheckBox1.Value
If Not .Locked Then
.BackColor = vbWindowBackground
Else
.BackColor = vbButtonFace
End If
End With
End Sub

hth,

Doug
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top