Soft and Hard Return Chars and Paragraph Count

B

Boram

I'm having trouble getting the correct paragraph count for a document
after stripping it of the soft return/vertical tab character (Chr(11))
and replacing it with the carriage return character (Chr(13)).

Even after saving, closing and reopening the target file to ensure
that ActiveDocument has been refreshed, the paragraph count still
turns out to be incorrect.

The following code demonstrates this bug:

'***************************************************************
Sub Test()

'Create file
Documents.Add

'Add 9 vert tab chars to the initial carriage return char
For i = 1 To 9
Selection.TypeText Chr(11)
Next i

'Set breakpoint here, verify that CountBefore = 1
CountBefore = ActiveDocument.Paragraphs.Count

'Replace vertical tab chars with paragraph chars
ActiveDocument.Range.Find.Execute FindText:=Chr(11), _
ReplaceWith:=Chr(13), _
Replace:=wdReplaceAll

'Set breakpoint here, verify that CountAfter = 1, although I want
'this to be 10
CountAfter = ActiveDocument.Paragraphs.Count

End Sub
'***************************************************************

The Paragraphs Collection doesn't get updated and Word behaves as if
it knows that the replaced characters used to be soft return
characters (Chr(11)).

Thanks in advance,
Boram
 
S

Stephanie Krieger

Hi, Boram,

Chr(13) is a carriage return character, but not seen by
Word as being exactly the same as a Word paragraph mark
(Note that you can place your insertion point after the
character on the same line -- even though Word won't
allow you to type after it ... but you can't do that with
a genuine paragraph mark.)

What you're trying to do will work if you use the UI
special character references for soft and hard returns
instead. Try this code instead of your existing
find\replace:

With Selection.Find
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With

The paragraph count will be correct.

Hope that helps -

Stephanie Krieger
author of Microsoft Office Document Designer (Microsoft
Press)
e-mail (remove spaces): MODD_2003 @ msn . com
blog: arouet.net
 

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