View Single Post
 
Old 09-12-2012, 09:01 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Try something along these lines:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim strFnd As String, wdDoc As Document, i As Long, j As Long
strFnd = InputBox("What is the Text to Find")
If Trim(strFnd) = "" Then Exit Sub
With ActiveDocument.Range
  j = .End
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^94[!^94]"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found = True
    With .Duplicate
      .Start = .Start + 1
      .MoveEndUntil Cset:="^", Count:=wdForward
      If InStr(.Text, strFnd) Then
        If wdDoc Is Nothing Then Set wdDoc = Documents.Add
        i = i + 1
        While .Characters.First = vbCr
          .Start = .Start + 1
        Wend
        .Copy
        With wdDoc.Range
          .InsertAfter Chr(12) & "Instance: " & i & vbCr
          .Characters.Last.Paste
          While .Characters.Last.Previous.Previous = vbCr
            .Characters.Last.Previous.Previous.Delete
          Wend
        End With
      End If
      If .End = j Then Exit Do
    End With
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
If Not wdDoc Is Nothing Then wdDoc.Characters.First.Delete
Set wdDoc = Nothing
Application.ScreenUpdating = True
MsgBox i & " instances found."
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 09-20-2012 at 10:01 PM.
Reply With Quote