"Visible" NL

B

Bob

In a document-reformatting macro that basically works, I replace page breaks
with blank lines by using the following:

With Selection.Find
.Text = "^m"
.Replacement.Text = vbCrLf
(snip - other parameters removed for this note)
End With
Selection.Find.Execute Replace:=wdReplaceAll

This works well, except it inserts [NL] (Character10) (represented here by
an asterisk) at the beginning of the following line.

Original:
End of previous page text.
---Page Break---
Start of next page text...

After macro:
End of previous page text.
(Paragraph Symbol)
*Start of next page text...

I wrote a macro to display the ASCII code for the character; that's how I
found out it is the LineFeed character. On my computer, this character
looks like a blank space. On a colleague's computer, it is a box. In
either case, it kinda messes up the formatting.

Rewriting the macro to replace with vbCr works, but I'm still wondering why,
when using vbCrLf, the character "take up space". I've used vbCrLf before,
and it doesn't seem to put visible space in a line of text. Any ideas?

As a follow-on, is the paragraph symbol only Chr(13)? Doesn't this yield
odd results if I cut and paste into a text document?

Thanks,
Bob
 
T

Tony Jollans

As you seem to have worked out, it's the "Lf" out of "vbCrLf". VBA has three
different codes 'new line' for different situations and you should use the
appropriate one. In this situation none of them are appropriate.

Word uses the "Cr" character to *represent* a paragraph mark - it is,
however, only a representation and to get a 'proper' paragraph mark, you
should use Word's built in code of "^p" instead.
 

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