![]() |
|
#6
|
||||
|
||||
|
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] |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
macro to find a character and insert space so autocorrect will expand
|
redzan | Word VBA | 3 | 05-22-2014 04:22 PM |
| Insert space in front of a numberd list MS Word | ekesawi | Word | 1 | 12-05-2012 07:21 PM |
Envelope Printing is off target - need help please!
|
mylan | Word | 2 | 10-24-2012 12:24 PM |
| Send OFT when target email arrives | RandWald | Outlook | 0 | 11-11-2011 10:52 AM |
Target line on a excel graph
|
leroytrolley | Excel | 1 | 01-16-2009 04:19 PM |