Re: Search for paragraph, format, & continue this through rest of
- From: LDMueller <LDMueller@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 20 Feb 2006 05:01:27 -0800
I assumed I was to only use your code and not mine. When I ran it, it came
back with a "Run-time error '5': Invalid procedure call or argument" on
pstring = Mid(prange.Text, 16, Len(prange) - 32)
"Doug Robbins - Word MVP" wrote:
I believe that I understood what you wanted to do and I think that the macro.
that I gave you should do it, unless the tags are not exactly as you
indicated.
If the tags are not exactly as you indicated, what are they?
If the tags are correct, what happened when you ran the macro?
--
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:0F274D3A-5DC7-43AF-894C-D5B95C77AECC@xxxxxxxxxxxxxxxx
Doug,
Thank you so much for the quick response. Unfortunately, this didn't work
and perhaps I didn't explain it well enough and more than likely the code
I
provided mislead you (sorry).
The reason my document has the "KeepTogetherTag" as the beginning of the
paragraph and the "KeepTogetherTag1" as the end of the paragraph is
because
the paragraphs themselves are different sizes and in different locations
throughout the document.
My main objective is to go through the document, highlight what is between
the tags and format this paragraph to "Keep with Next". After it does
one,
it searches again, locates another paragraph, formats it and continues
doing
this to the end of the document.
I hope this makes sense.
Thanks, Leigh
"Doug Robbins - Word MVP" wrote:
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:
- Re: Search for paragraph, format, & continue this through rest of
- From: Helmut Weber
- Re: Search for paragraph, format, & continue this through rest of
- From: Doug Robbins - Word MVP
- Re: Search for paragraph, format, & continue this through rest of
- References:
- Search for paragraph, format, & continue this through rest of docu
- From: LDMueller
- Re: Search for paragraph, format, & continue this through rest of docu
- From: Doug Robbins - Word MVP
- Re: Search for paragraph, format, & continue this through rest of
- From: LDMueller
- Re: Search for paragraph, format, & continue this through rest of
- From: Doug Robbins - Word MVP
- Search for paragraph, format, & continue this through rest of docu
- Prev by Date: Re: Macros
- Next by Date: Re: Names of subdirectories in the registry
- Previous by thread: Re: Search for paragraph, format, & continue this through rest of
- Next by thread: Re: Search for paragraph, format, & continue this through rest of
- Index(es):
Relevant Pages
|