Formatting text in MsgBox?

M

Maury Markowitz

I have a lot of error messages and warnings I'd like to make readable, but I
can't figure out how. Is there a way to put a "return" into the box, at a
minimum?
 
A

Allen Browne

In code:
MsgBox "Try This" & vbCrLf & "with a second line"

In a macro:
MsgBox "Try This" & Chr(13) & Chr(10) & "with a second line"

If you want anything more powerful than that, create a small unbound form
that can display the messages as you desire.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
news:[email protected]...
 
S

Sprinks

Hi, Maury.

You can use the VBA constant vbCRLF to insert a new line, such as:

strErrMsg = "No value entered in the State field." & vbCRLF & "Please
reenter."
MsgBox strErrMsg

Hope that helps.
Sprinks
 
M

Maury Markowitz

Sprinks said:
You can use the VBA constant vbCRLF to insert a new line, such as:

Perfect, thanks! Is there a list of these? I'd like to use bullets and such
as well.

Maury
 
S

Sprinks

Search VBA Help for Constants, and select the topic Visual Basic Constants.
Some of the Keycode constants could be used for this purpose. Also, you can
use any arbitrary ASCII character if you know its code by calling the Chr$
function. Beyond that, Allen's suggestion offers a great deal of flexibility.

Sprinks
 
D

Douglas J. Steele

You can't use things like bullets in a message box: the closest you'll be
able to come is insert a character (using Chr, as Sprinks suggested), but
you won't be able to get proper indentation if the text extends past a
single line.

If you really need such functionality, you're probably better off creating
your own message box form, and use an RTF control on it. See the free RTF
control Stephen Lebans has at http://www.lebans.com/richtext.htm
 
Top