Need to find end of true paraghaph.

I

ISay

I've been through all posts to find/replace paragraph marks. My problem is
that every line ends with a pilcrow, paragraph mark,; there are no ^p^p to
determine the actual end of paragraph. I realize that I will have to
manually edit each paragraph but we are talking more than 150 pages per
document.

Is there any way of finding shortened lines which might indicate the end of
a paragraph so that I could insert ^p^p for easier find/replace. How would I
define a short line, were it even possible. I realize it wouldn't be
foolproof but it might cut down on manually editing each and every paragraph.
 
G

Greg Maxey

USay,

You could run this macro:

Sub UnQualifiedLines()
Dim CharCount As Integer
Dim tCount As Integer
Dim Qualifier As String
Qualifier = InputBox("Enter minimum line length:", "Line Length", 1)
tCount = ActiveDocument.ComputeStatistics(wdStatisticLines)
Selection.HomeKey wdStory
Do While tCount > 0
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
CharCount = Selection.Characters.Count
tCount = tCount - 1
If CharCount < Qualifier Then
Selection.TypeText vbCr
End If
Selection.Collapse wdCollapseStart
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Loop
Selection.HomeKey wdStory
End Sub


For help running macros see: http://www.gmayor.com/installing_macro.htm
 
G

Graham Mayor

I guess it depends how short a line. The following will add a second
paragraph mark after each paragraph that is .8 of the first paragraph. If
the first paragraph is a short sub heading, change the number in
Paragraphs(1) to the number of the first full length paragraph.

Sub ShortParas()
Dim iNum As Integer
iNum = ActiveDocument.Paragraphs(1).Range.Characters.Count
MsgBox iNum & vbCr & Int(iNum * 0.8)
For i = ActiveDocument.Paragraphs.Count To 1 Step -1
If ActiveDocument.Paragraphs(i).Range.Characters.Count < Int(iNum * 0.8)
Then
ActiveDocument.Paragraphs(i).Range.InsertAfter vbCr
End If
Next i
End Sub

http://www.gmayor.com/installing_macro.htm


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Greg Maxey

Graham,

That is better. I had modified the code on hand from my
http://gregmaxey.mvps.org/Count_Lines_of_Text.htm which needs Selection.

Joining the two gives:

Sub ShortParas()
Dim Qualifier As String
Dim i As Long
Qualifier = InputBox("Enter minimum line length:", "Line Length", 1)
For i = ActiveDocument.Paragraphs.Count To 1 Step -1
If ActiveDocument.Paragraphs(i).Range.Characters.Count < Qualifier Then
ActiveDocument.Paragraphs(i).Range.InsertAfter vbCr
End If
Next i
End Sub
 
I

ISay

Greg and Graham:

I have never been able to get my mind around more than the very simple
macros I create. I've tried all your suggestions but I get a "syntax error"
message and it starts to debug, I don't know what to do at this point. I
know it wants me to enter a parameter but I don't know just exactly what it
wants.

I tried to comprehend your "Idiot's Guide" but I'm just not that smart and
the instructions are for Word 2007, I'm still using Word 2003. It requires
more than just copy/paste and may as well have been written in Greek. I have
a small and old brain and it's getting smaller and older '-)

I really appreciate the help, you've given me many solutions to my editing
problems.
 
G

Graham Mayor

The problem with my macro is that 'Then' has wrapped to the following line
in the newsgroup editor. Greg's should be OK as it stands

To correct mine, copy and paste the following

Sub ShortParas()
Dim iNum As Integer
iNum = ActiveDocument.Paragraphs(1).Range.Characters.Count
MsgBox iNum & vbCr & Int(iNum * 0.8)
For i = ActiveDocument.Paragraphs.Count To 1 Step -1
If ActiveDocument.Paragraphs(i).Range.Characters.Count _
< Int(iNum * 0.8) Then
ActiveDocument.Paragraphs(i).Range.InsertAfter vbCr
End If
Next i
End Sub

The Idiots Guide is for both Word 2003 and 2007. Where they differ
alternative illustrations are provided.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
I

ISay

I woke up with what I thought was a clear brain. I had 2 cups of tea and
read your "Idiot's Guide" (is everything below 'Modules' important?)

I edited the macro (excluding 'Modules') and ran it. A window popped up:
12
9
OK
I clicked OK. At which point the document locked and I had to use "End
Program". Would usiing the 'Modules' information have made the difference?

I'm sorry to be such a bother but this editing problem happens quite
frequently and I would like to get it sorted so I don't have to edit each
paragraph manually.
 
G

Graham Mayor

If the message box displays 12 and 9 then the first line in your document is
only 12 characters long, which is not a suitable line to base the macro on.
You need to count down the paragraphs and find a line that goes across the
page, then change the '1' in the line

iNum = ActiveDocument.Paragraphs(1).Range.Characters.Count

to the number of the paragraph that fills the page width eg

iNum = ActiveDocument.Paragraphs(3).Range.Characters.Count

Or use Greg's macro which asks you to input the minimum number of characters
that will appear on a line before an extra paragraph mark is added. With a
large document the macro may take some time to run. It doesn't necessarily
follow that the document has locked.

The module issue is not the problem here.

Can you mail me (to the link on the home page of my web site) a couple of
pages of the document so I can see for myself what the issue is?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
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