how many linefeed in a paragraph

L

Le Nordiste

Hi from Meudon (France)

I want to know the number of line feed (char(11)) in a paragraph.

My problem is to pick up a paragraph -starting by " 1" in my .doc,
and to count the number of ^011 in this paragraph.


Thanks in advance for your collaboration.

Le Nordiste ( the Northman)
 
G

Graham Mayor

The following will look through a documnent for a paragraph beginning " 1"
(a space followed by 1) and count the number of line feeds in that paragraph

Dim orng As Range
Dim sFeed As Long
sFeed = 0
On Error GoTo NotFound
With ActiveDocument
For i = 1 To .Paragraphs.Count
Set orng = .Paragraphs(i).Range
With orng
If .Characters(1) = Chr(32) And .Characters(2) = "1" Then
While .Find.Execute(Chr(11)) = True
sFeed = sFeed + 1
Wend
MsgBox "Paragraph " & i & " Contains " _
& sFeed & " Line Feed Characters"
Exit Sub
End If
End With
Next i
End With
Exit Sub
NotFound:
MsgBox "No matching paragraph!", vbInformation


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

Le Nordiste

Thanks Graham,

I have only to adapt at my own problem, but your code perfectly work.


le Nordiste.
 
L

Le Nordiste

My original text looks like :

Table_01chr((13)
1 field_01chr(11)
2 field_02 chr(11)
3 …

11field_11chr(11)
12 field_12chr(11)
chr(13)
table_02chr(13)
1 field_01chr(11)
2 field_02 chr(11)
3 …

10 field_10chr(11)
11 field_11chr(11)
chr(13)
Table_03chr(13)

Your code, Graham, well detect the paragraphs but when the field
paragraph is seen,
the code don't stop at the first chr(13) just after the last field of
this table.
In fact it goes on until the last chr(13).

Where am i wrong ?


Thanks
 
L

Le Nordiste

This is my "YourCode" adaptation
……
With ActiveDocument
For i = 7 To 12 '.Paragraphs.Count
Set orng = .Paragraphs(i).Range
MsgBox i & " : " & orng
With orng
'??????
If .Characters.Count = 1 Then
GoTo ProchainParagraphe
Else
If .Characters(1) = Chr(32) And .Characters(2) = "1"
Then
While .Find.Execute(Chr(13)) = True
sFeed = sFeed + 1
Wend
MsgBox "Paragraph " & i & " Contains " & sFeed & "
Line Feed Characters"
End If
End If
'????????
End With
ProchainParagraphe:
Next i
End With
……
 
G

Graham Mayor

You have changed the macro to count paragraphs within a paragraph? There are
no paragraphs within a paragraph. A paragraph is terminated by the paragraph
mark.
Can you send me a sample document and EXACTLY what you want to recover from
it to the link on my web site?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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