Multiline Messagebox in VBA

  • Thread starter Thread starter Joe
  • Start date Start date
J

Joe

Hi all,

I wanted a Multiline Messagebox in VBA.
I tried the following code but an error ("Object Required") comes.

MsgBox ("Some text" & ControlChars.NewLine & "More text")
Is it because of the .newline? How can I get a multiline msgbox?

mine is excel 2003 (SP2)


Thanks
Joe
 
Simply use one of the built-in VBA constants to move to the next line....

MsgBox "Some text" & vbNewLine & "More text"

or...

MsgBox "Some text" & vbCrLf & "More text"

or even....

MsgBox "Some text" & vbLf & "More text"

or even....

MsgBox "Some text" & vbCr & "More text"

VBA seems to be tolerant of almost anything that says 'go to another line'.

Rick
 
I read recently that vbNewLine was slightly faster than vbCrLf. vbCr and
vbLf may not give the same results.

- Jon
 
I'm not sure about any speed advantage, but the purpose of vbNewLine is that
it is a platform (Windows or Mac) specific newline character or character
sequence. That is, in Windows, vbNewLine is the same as vbCrLf; however, on
a Mac, vbNewLine is the same as vbCr. That means if you are trying to inject
a newline character sequence into a string of text, using vbNewLine relieves
you of having to know what operating system your code will be run on. With
that said, it is my understanding that the MessageBox statement will treat
any of vbNewLine, vbCrLf, vbCr and vbLf all the same... as a newline
character (sequence) no matter which operating system the code is run on.
While the following link is directed at XL2000, the part described above is,
again my understanding, universally applicable for the various Office
products as well as the compiled version of VB.

http://support.microsoft.com/kb/211774

Rick
 
Back
Top