Re: Search for paragraph, format, & continue this through rest of docu
- From: "Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx>
- Date: Mon, 20 Feb 2006 06:15:52 +0100
The following should do it:
Dim prange As Range, pstring As String
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="KeepTogetherTag", MatchWildcards:=False,
Wrap:=wdFindContinue, Forward:=True) = True
Set prange = Selection.Paragraphs(1).Range
pstring = Mid(prange.Text, 16, Len(prange) - 32)
prange.Text = pstring & vbCr
prange.ParagraphFormat.KeepWithNext = True
Loop
End With
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"LDMueller" <LDMueller@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B06DA3C4-0DF7-4147-AF00-2CEE71136C9F@xxxxxxxxxxxxxxxx
Hello,
I have Word 2003. I'm trying to search and highlight a paragph which has
the word "KeepTogetherTag" as the beginning of the paragraph and the word
"KeepTogetherTag1" as the end of the paragrah. Once this paragraph is
highlighted, I to to Format, Paragraph, Line and Page Breaks and under
Pagination I want to ensure only "Keep with Next" is checked.
Below, I've provided my code to do this.
My problem is this. Once I select and format the first paragraph, I need
it
to locate the next paragraph like this, format it and continue to the end
of
the document.
I can write a little VBA and have tried Do While and Loop, but can't seem
to
write it correctly so nothing works.
Any assistance you provide would be greatly appreciated!
Sub FormatP()
' Search document for the word KeepTogetherTag
Selection.Find.ClearFormatting
With Selection.Find
.Text = "KeepTogetherTag"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' Once you find KeepTogetherTag, go to beginning of the line
' and press F8 to extend next search
Selection.HomeKey Unit:=wdLine
Selection.Extend
Selection.Find.ClearFormatting
' Search document for the word KeepTogetherTag1
' Now a paragraph is highlighted so I can format it to keep together
With Selection.Find
.Text = "KeepTogetherTag1"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
' Format selected paragraph by going to Format, Paragraph, Line and Page
Breaks
' and under Pagination make sure only "Keep with Next" is checked
With Selection.ParagraphFormat
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
.WidowControl = False
.KeepWithNext = True
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
End With
' Move down one line so you can search for the next paragraph
' beginning with KeepTogetherTag
Selection.MoveDown Unit:=wdLine, Count:=1
End Sub
.
- Follow-Ups:
- References:
- Prev by Date: Re: Names of subdirectories in the registry
- Next by Date: Re: Search for paragraph, format, & continue this through rest of
- Previous by thread: Search for paragraph, format, & continue this through rest of docu
- Next by thread: Re: Search for paragraph, format, & continue this through rest of
- Index(es):
Relevant Pages
|