View Single Post
 
Old 10-18-2019, 05:29 PM
pike pike is offline Windows 7 64bit Office 2010
Novice
 
Join Date: Jul 2019
Location: Alstonville
Posts: 4
pike is on a distinguished road
Default

maybe just

Code:
Option Explicit
Sub FormatNumbers()
    Dim lngdb As Long
    If Selection.Type = wdSelectionIP Then
        ActiveDocument.Range(0, 0).Select
        lngdb = wdFindContinue
    Else
        lngdb = wdFindStop
    End If
    With Selection.Find
        .ClearFormatting
        .Text = "[0-9]{4,}"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = lngdb
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
        Do While .Execute
            Selection.Text = Format$(Selection.Text, "#,##0")
            If lngdb = wdFindContinue Then
                Selection.Collapse wdCollapseEnd
            Else
                Exit Sub
            End If
        Loop
    End With
End Sub

Last edited by pike; 10-18-2019 at 08:11 PM.
Reply With Quote