View Single Post
 
Old 06-26-2017, 02:56 AM
eduzs eduzs is offline Windows 10 Office 2010 32bit
Expert
 
Join Date: May 2017
Posts: 266
eduzs is on a distinguished road
Default

Wildcard is like magic.
Thanks again!

"Final" code, for collaboration purposes:

Quote:
Sub Text_Cleaner()

Dim i As Long, opMsg As Integer, oRng As Range, oPara As Range, aProc, aSubs

aProc = Array("^255", "^13^32", "^32{1;}^13", "^13^32{1;}", "^13{2;}", "^32{2;}", "([!.:;""])^13")
aSubs = Array("", "^p", "^p", "^p", "^p", " ", "\1 ")

If Selection.Words.Count = 1 Then

Set oRng = ActiveDocument.Range
opMsg = 1

Else

Set oRng = Selection.Range
opMsg = 2

End If

If MsgBox("Clean-up " & IIf(opMsg = 1, "activedocument", "selected range") & "?", vbYesNo + vbExclamation, " CONFIRMATION!") = vbNo Then Exit Sub

Application.ScreenUpdating = False

For i = 0 To UBound(aProc)

With oRng.Find
.ClearFormatting
.Text = aProc(i)
.Replacement.Text = aSubs(i)
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With

Next i

Set oPara = oRng.Paragraphs(1).Range

If Left(oPara.Text, 1) = " " Then oPara.Text = Right(oPara.Text, Len(oPara.Text) - 1)

If Len(ActiveDocument.Range.Paragraphs.Last.Range) = 1 Then ActiveDocument.Range.Paragraphs.Last.Range.Delete

Application.ScreenUpdating = True

End Sub
__________________
Backup your original file before doing any modification.
Reply With Quote