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

Soft and Hard Return Chars and Paragraph Count by Stephanie

Stephanie
Wed Aug 25 14:16:34 CDT 2004

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
>-----Original Message-----
>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
>.
>

Re: Soft and Hard Return Chars and Paragraph Count by theyoonaboramer

theyoonaboramer
Thu Aug 26 10:06:08 CDT 2004

Thanks Stephanie that worked!

Boram