MrExcel Publishing
Your One Stop for Excel Tips & Solutions

input box - colour

Posted by Qroozn on December 17, 2001 2:24 PM

i have an input box which is used to request a password. can i make this text (when inputed) come up as a selected colour... for eg. red.


Posted by DaK on December 17, 2001 2:42 PM

Look at the forecolor in the properties window of the text box. You can select the color of the text there. As for red, you will probably have to know the hex number for red as it is not one of the options for color.
Good luck,

Posted by Qroozn on December 17, 2001 3:06 PM

Thanks for that. I'll check it out.
I mainly want to colour it white so that it doesnt show the password while it is being typed.

Posted by Duane Kennerson on December 17, 2001 3:29 PM

Re: well you can try this too!

Place this code in the form with your text box. You can change the character that is displayed to anything , I just happen to have it as a "*".

Private Sub (name of your textbox)_Change()
'create the star character for the password

(name of your textbox).PasswordChar = "*"

End Sub

Give it a try, I think its probably more what you are looking for.

Posted by Qroozn on December 17, 2001 3:40 PM

Re: well you can try this too!

i am not using a form though. it is just an input box where.....

MsgBox "Password Required!", vbOKOnly, "ACCESS RESTRICTED"
Password = InputBox("Please enter the password", "ACCESS RESTRICTED")
If Password = "Password7" Then
will it still work the same way?

Posted by DaK on December 17, 2001 3:55 PM

Re: well you can try this too!

Not sure, I would probably try placing it between "password = InputBox" & the If statement. Experiment and try. Sorry for the confusion.


Posted by Qroozn on December 17, 2001 4:15 PM

Not quite

Sorry. didn't work.

Thanks anyway. I guess i started it the long way... but its rthe only way i know how. I'll keep you informed if i solve it.

Posted by DaK on December 17, 2001 5:28 PM

Re: Not quite

I looked around and unfortunatley the input box text color is not optional. If you want the flexibily, I would get rid of the msgbox code and Create two user forms. Name one "frmPassword" and the other "frmAccess".

Place this code in a module. Wherever you wanted to call the password msgbox, just put "password" in its place so that it will call this procedure instead.

Sub password()
'show the password form

end sub

Build your first form to have a text box and a button.
Name the text box "txtPassword".
Name the button "cmdOK" and put OK in the button caption.

Code for the ok button

private sub cmdOK_click()


if txtPassword = "Password7" then
txtPassword="" ' clear the textbox
frmPassword.hide ' hide the form ' show the new form
fmrPassword.hide ' hide the form and do nothing

end sub

Build another form and name it "frmAccess".
Put a label on the form and a button on the form.
In the caption for your label put, " You now have access" (or whatever).

Name the button "cmdOK" and put OK in the caption of the button.
The code for the button

private sub cmdOK_click()
'give them access

'put whatever code you want that gives them
'access here. I would presume you would put
'the same code here as you did for the correct response from your input box.

frmAccess.hide 'hide the form

end sub

Try it if you want, if you have ?'s, you know how to ask. Good luck.


Posted by Ivan F Moala on December 17, 2001 7:37 PM

if you really want to change the colour to white
then you will have to change the system text colour
The down side is that ALL windows text will be white can always change it back.

Try this code;

Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Function SetSysColors Lib "user32" (ByVal nChanges As Long, lpSysColor As Long, lpColorValues As Long) As Long

Sub ChangeColorDefaultText()
Dim Kolor
Dim CurKolor
'Black 0 0 0
'Blue 0 0 255
'Green 0 255 0
'Cyan 0 255 255
'Red 255 0 0
'Magenta 255 0 255
'Yellow 255 255 0
'White 255 255 255
CurKolor = GetSysColor(8)
If CurKolor <> 0 Then
'restore to Default
Kolor = SetSysColors(1, 8, RGB(0, 0, 0))
'color it white
Kolor = SetSysColors(1, 8, RGB(255, 255, 255))
End If

End Sub