rmbrown
asked on
Word Macro to Select Multiple Paragraphs Based On Content
I have a document containing multiple short paragraphs. The paragraphs are written in groups where the first starts with "Software Specification". There are three more paragraphs immediately following and then a Fifth that starts with "Area Path".
I need a macro that will look through the entire document, adjusted the selected text to be a block of the five paragraphs, put borders around all, then move on to the next block. I know how to do the borders once the block is selected but not how to cycle through the blocks.
Once that's completed, I want to cycle through, paragraph by paragraph, and if it begins with "Software Specification" set the shading. Again, I can do the shading on a selection but don't know how to cycle through each paragraph looking for the correct one.
I need a macro that will look through the entire document, adjusted the selected text to be a block of the five paragraphs, put borders around all, then move on to the next block. I know how to do the borders once the block is selected but not how to cycle through the blocks.
Once that's completed, I want to cycle through, paragraph by paragraph, and if it begins with "Software Specification" set the shading. Again, I can do the shading on a selection but don't know how to cycle through each paragraph looking for the correct one.
ASKER
Here's what I tried... Only the first paragraph was selected and bordered. Thoughts?
Sub PutBordersAroundSelection( )
Dim rng As Range
Dim brd As Border
Set rng = ActiveDocument.Range
With rng.Find
.Text = "Software Specification*^13Area Path*^13"
.MatchWildcards = True
Do While .Execute
With Selection.Borders(wdBorder Top)
.LineStyle = Options.DefaultBorderLineS tyle
.LineWidth = Options.DefaultBorderLineW idth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorder Left)
.LineStyle = Options.DefaultBorderLineS tyle
.LineWidth = Options.DefaultBorderLineW idth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorder Bottom)
.LineStyle = Options.DefaultBorderLineS tyle
.LineWidth = Options.DefaultBorderLineW idth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorder Right)
.LineStyle = Options.DefaultBorderLineS tyle
.LineWidth = Options.DefaultBorderLineW idth
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorder Horizontal )
.LineStyle = Options.DefaultBorderLineS tyle
.LineWidth = Options.DefaultBorderLineW idth
.Color = Options.DefaultBorderColor
End With
rng.Collapse wdCollapseEnd
rng.End = ActiveDocument.Range.End
Loop
End With
End Sub
Sub PutBordersAroundSelection(
Dim rng As Range
Dim brd As Border
Set rng = ActiveDocument.Range
With rng.Find
.Text = "Software Specification*^13Area Path*^13"
.MatchWildcards = True
Do While .Execute
With Selection.Borders(wdBorder
.LineStyle = Options.DefaultBorderLineS
.LineWidth = Options.DefaultBorderLineW
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorder
.LineStyle = Options.DefaultBorderLineS
.LineWidth = Options.DefaultBorderLineW
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorder
.LineStyle = Options.DefaultBorderLineS
.LineWidth = Options.DefaultBorderLineW
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorder
.LineStyle = Options.DefaultBorderLineS
.LineWidth = Options.DefaultBorderLineW
.Color = Options.DefaultBorderColor
End With
With Selection.Borders(wdBorder
.LineStyle = Options.DefaultBorderLineS
.LineWidth = Options.DefaultBorderLineW
.Color = Options.DefaultBorderColor
End With
rng.Collapse wdCollapseEnd
rng.End = ActiveDocument.Range.End
Loop
End With
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window