Formatting text in MsgBox?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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]...
 
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
 
In your code, where you want the line to break, put a "& vbCr" to add a
carraige return; use two of them to put a blank line between the two
sentences. So it would look like:

MsgBox "Sorry, but you picked the wrong values." & vbCr & vbCr _
& "Please try again."

You don't need to break the line in the code using the "_", but I like to
do it for readability of my code.
 
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
 
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
 
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
 

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

Similar Threads

Excel [VBA] Check from a cell into another sheet and bring back result in MsgBox 0
Date Warning MsgBox 2
Computer Crashing 8
Rich Text Format 0
MsgBox 1
Suppress MsgBox 7
MsgBox 5
MsgBox..Expected End of Statement 2

Back
Top