Coloured Text in a VBA User Form

J

John... Visio MVP

Is there a way to set a label's colour to Red in a User Form so that it can
be used as an error message and stand out?

John... Visio MVP
 
J

Jay Freedman

John... Visio MVP said:
Is there a way to set a label's colour to Red in a User Form so that
it can be used as an error message and stand out?

John... Visio MVP

The statement you're looking for is

myLabel.ForeColor = RGB(255, 0, 0) ' red

You might want to combine that with

myLabel.Font.Bold = True

There are a few ways to handle this.

- If the label should be visible and red whenever the userform is shown
(i.e., the userform is shown only when the error occurs), just set the
label's ForeColor property in the Properties pane in design mode. No extra
code is needed.

- If the label should be red whenever it appears, but it appears only when
the error occurs, then set the ForeColor in the Properties pane and also set
its Visible property to False; then toggle Visible to True in the error
handler.

- If the label should appear all the time, but you want to change the color
to red when it indicates an error, then use the above code in the error
handler. If you need to change it back to black later, set .ForeColor =
RGB(0, 0, 0).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

John... Visio MVP

Thanks Jay, I was looking for something directly associated with the font. I
forgot about the ForeColor.
For my purpose, I will set the ForeColor, and I will be blanking out the
message, so there is no need to play with the visibility.

John...
 
H

Helmut Weber

Hi John,

try the forecolor property.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
J

John... Visio MVP

Helmut Weber said:
Hi John,

try the forecolor property.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP


Thanks Helmut. For some reason my mind was thinking text rather than label,
so I was looking for something to do to the font rather than playing with
the foreground colour of the label.

John...
 

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

Top