Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabled Textbox Font Colour

Tags:

excel

vba

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.

like image 407
court_k Avatar asked Oct 12 '25 00:10

court_k


1 Answers

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
like image 166
Nathan_Sav Avatar answered Oct 14 '25 13:10

Nathan_Sav