Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

find and replace formatting in sentence following Heading 2 style

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Freddi - 07 May 2006 18:53 GMT
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!
Helmut Weber - 07 May 2006 19:36 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Helmut Weber - 07 May 2006 20:31 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.