View Single Post
 
Old 08-29-2017, 08:49 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,371
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use something along the lines of:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = InputBox("What is the Text to Find")
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    With .Duplicate
      .Collapse wdCollapseStart
      .Text = "Prefix "
      .Font.Italic = True
    End With
    With .Duplicate
      .Collapse wdCollapseEnd
      .Text = " Suffix"
      .Font.Bold = True
    End With
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
This code simply adds an italicized 'Prefix' & 'Suffix' to each found instance; you could replace those with whatever other code you want, including calls to functions/macros.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote