View Single Post
 
Old 06-19-2014, 07:13 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, StrFnd As String, CharExcl As String, StrTmp As String
CharExcl = ",.(?)/\¬(!)£$%^&(*)(-)+=’'”@(#)~:;|<>¦_{}([)()"

StrFnd = Trim(InputBox("What is the Text to Find"))
If StrFnd = "" Then Exit Sub
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = StrFnd
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    i = i + 1
    With .Duplicate
      StrTmp = .Text
      If Not .Characters.First.Previous.Text Like _
       "[ ‘'“" & Chr(160) & Chr(12) & vbCr & vbTab & "]" Then
        StrTmp = " " & StrTmp
      End If
      If Not .Characters.Last.Next.Text Like _
        "[ " & CharExcl & Chr(160) & Chr(12) & vbCr & vbTab & "]" Then
        If Not .Characters.Last.Next.Text = "]" Then
          StrTmp = StrTmp & " "
        End If
      End If
    End With
    If .Text <> StrTmp Then .Text = StrTmp
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
MsgBox i & " instances found."
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote