View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Line Continuation issue

Text strings constants (which are defined by a starting and ending quote
mark) must all appear on the same line. When you put your line continuation
character in, you left the quote marks unbalanced on the original line (no
ending quote mark) and on the newly created line (no starting quote mark).
You *cannot* simply put them in like this though...

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

because VB will not know what to do with the two parts. It would be like if
you wrote this line of code...

StrVar = "First part of sentence" "Next part of sentence"

To handle both of these, you would need an ampersand between the two text
string constants in order to concatenate them together. So, your original
line line of code could have been written this way...

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet. " & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

Doing it this way, however, will just link the two text string constants
together as if they had been written in a single line. You would do it this
way in order to "neaten" up your code on the screen in order that *you*
could more read it more easily (as opposed to having a long text string
possibly trail off the screen because it is too long to display within the
given the code window's width. To do what I think you asked... display the
two individual text string constants on two separate lines within the
MessageBox... you have to tell VB to put a line separating character between
them. The help files say that you can use a Line Feed character, a Carriage
Return or a combination of Line Feed and Carriage Return characters (in that
order). VB has predefined characters for these line separating characters
and they are, in the same order I listed them in, vbLf, vbCr and vbLfCr. VB
also has an alternative constant for that last one... vbNewLine. So, using
vbLf as the separator, your original code line would be...

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet." & vbLf & _
"Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

Now, when VB creates the MessageBox message, it will display the two text
string constants on separate lines.

--
Rick (MVP - Excel)


"Bishop" wrote in message
...
What am I doing wrong? Here is the line of code:

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet. Have you
completed "" ""PFs?", vbYesNo, "Completed PFs")

But I want to use ' _' to continue the phrase on the next line but when I
do
this:

Msg = MsgBox("You have "" "" PFs loaded in the Tally Sheet. _
Have you completed "" ""PFs?", vbYesNo, "Completed PFs")

I keep getting "Expected: list separator or )"