find and replace formatting in sentence following Heading 2 style

F

Freddi

How would you do a find and replace to format the sentence following a
Heading 2 style throughout a large document? The text would need to be
changed from regular text to bold and italics. The defining mark would be
the period and two spaces immediately following a Heading 2 style containing
a tab. If any of you know the answer to this, please let me know. Thank you!
 
H

Helmut Weber

High Freddi,

can all be done, IMHO,
but first the conditions have to be defined more precisely.

Set a range to the whole doc
Search that range for a paragraph of style "heading 2".
while .execute
Set the range to the following paragraph.
Set the range's end to the first period in that paragraph.
Format it
set the range again from current end to end of doc
wend

Right?

The hint for the tab you mentioned and the 2 spaces
seems to be redundant.

Right?

Whether the spaces are bold and italic doesn't matter,
that is to say, only in theory.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

High Freddi,

using the assumptions from my former posting,
except that there are two ranges instead of one:

Sub Macro2()
Dim lPos As Long
Dim rDcm As Range
Dim rTmp As Range
Set rDcm = ActiveDocument.Range
Set rTmp = ActiveDocument.Range
With rDcm.Find
.Style = "Heading 2"
While .Execute
Set rTmp = rDcm.Paragraphs.Last.Next.Range
rTmp.Select ' redundant, for testing only
lPos = rTmp.Start
With rTmp.Find
.Text = "."
If .Execute Then
rTmp.SetRange Start:=lPos, End:=rTmp.End
rTmp.Select ' redundant, for testing only
rTmp.Font.Bold = True
rTmp.Font.Italic = True
End If
End With
Wend
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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