In Word, how can I automatically insert a comma between numbers?
I suspect there is a Find/Replace that would be more direct but this macro
should do what you are asking.
_ __ ______ __________________________
Sub AddCommasToNumbers()
Dim rngOriginal As Range
Dim strTemp As String
Application.ScreenUpdating = False
Set rngOriginal = Selection.Range
ActiveDocument.Range(0, 0).Select
With Selection.Find
.ClearFormatting
.Text = "[0-9]{4,}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
Do While .Execute
strTemp = Selection.Text
Selection.Text = Format$(strTemp, "#,##0")
Selection.Collapse wdCollapseEnd
Loop
End With
rngOriginal.Select
Application.ScreenUpdating = True
End Sub
______________________________________________
Steve Yandl
"sharris" wrote in message
...
When I am typing a document in Word (let's say a letter) and I type
numbers
with a comma such as 1,158, I use the number pad but have to go over to
the
letter pad for the comma. There should be a comma in the number pad. Is
there
any way to format with auto correct with the numbers being unknown, to
always
insert a comma after every number that is followed by three numbers
(1,111,111 or 1,158)? Or is there some other way that I don't know about,
such as automatically invoking a macro?
|