Reputation: 101
I've been looking around for a solution to my question, and have been unable to find one, so I thought I would ask here.
I have a userform with multiple text boxes on it that are disabled so the user cannot edit them. And I've noticed excel changes the font colour of disabled textboxes to a light grey. So I have been trying to change the font colour back to black for easier readability but have been unable to do so. I have tried changing the ForeColor in the properties window to black, and I've tried doing it via code, e.g.
Controls("Textbox" & i).ForeColor = vbBlack
But the textboxes still remain a light grey colour. Is there any way to change this?
edit: I have also considered changing the textboxes to labels but this would require a lot of work, which is fine but I'm hoping to find another potential solution.
Upvotes: 4
Views: 10047
Reputation: 21
Or, if you don't want even enter it - just put the Label in front of it with BackStyle = Transparent
Upvotes: 0
Reputation: 8531
You could use the .locked
property, like so
Private Sub UserForm_Click()
custom_lock Me.TextBox1
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
custom_unlock Me.TextBox1
End Sub
Function custom_lock(tb As MSForms.TextBox)
tb.ForeColor = vbRed
tb.Locked = True
End Function
Function custom_unlock(tb As MSForms.TextBox)
tb.ForeColor = vbBlack
tb.Locked = False
End Function
Upvotes: 4