A family of Microsoft word processing software products for creating web, email, and print documents.
My fault, sorry for the inconvenience.
I started with:
128-134
66-68
1340-346
350-359
126–29
And end up:
128–34
66–8
1340–6
350–9
126–9
As you have requested, use the following code.
Sub Elision_AK()
Dim StrA As String, StrB As String, i As Long, j As Long
Dim Delimiter As Variant
Dim Pattern
'Hypen, en dash
Delimiter = Array("-", ChrW(8211))
Pattern = "[" & Join(Delimiter, "") & "]"
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "<[0-9]{2,}" & Pattern & "[0-9]{2,}>"
.Replacement.Text = ""
.Wrap = wdFindStop
.MatchWildcards = True
.Forward = False
.Execute
End With
Do While .Find.Found
For j = 0 To UBound(Delimiter)
If InStr(.Text, Delimiter(j)) > 0 Then
StrA = Split(.Text, Delimiter(j))(0)
StrB = Split(.Text, Delimiter(j))(1)
Exit For
End If
Next
For i = 1 To Len(StrB)
If InStr(1, StrA, Left(StrB, i)) = 0 Then Exit For
Next
If i > 1 Then
StrB = Mid(StrB, i)
.Select
DoEvents
Select Case MsgBox("Replace with " & StrA & "-" & StrB & "?", vbYesNoCancel + vbQuestion, "Elision_AK")
Case vbNo
GoTo Skip
Case vbCancel
Exit Sub
End Select
.MoveStart wdCharacter, Len(StrA)
.Text = ChrW(8211) & StrB
End If
Skip:
.Collapse wdCollapseStart
.Find.Execute
Loop
End With
End Sub