Decimal Comma Macro

* * *

Description

This is a Visual Basic Macro which will run on Microsoft Word. It replaces commas between numerical digits with periods.

To replace [0-9],[0-9] with [0-9].[0-9]

For example, it will replace 3,4 with 3.4

Be careful with some software (e.g. Unix) commands like 111,12 33,01, etc., where the comma should not be replaced.

This macro is useful when translating German texts to English. It changes the comma in numbers to a period.


Decimal Comma Macro Code

Public Sub MAIN()

Dim TempStr$

Dim a$

Dim b$

Dim c$

WordBasic.StartOfDocument

Loop_:

WordBasic.CharLeft 1

WordBasic.EditFind Find:="[0-9],[0-9]", Direction:=0, MatchCase:=0, WholeWord:=0, PatternMatch:=1, SoundsLike:=0, Format:=0, Wrap:=1

If WordBasic.EditFindFound() = 0 Then

Rem "3,4" not found, exit

GoTo Allover:

End If

Rem Save "3,4"

TempStr$ = WordBasic.[Selection$]()

Rem Get first char from string i.e. "3"

a$ = WordBasic.[Left$](TempStr$, 1)

Rem Get last char from string i.e. "4"

b$ = Mid(TempStr$, 3, 1)

Rem Form "3.4"

c$ = a$ + "." + b$

Rem Replace "3,4" with "3.4"

WordBasic.CharLeft 1

WordBasic.EditReplace Find:=TempStr$, Replace:=c$, Direction:=0, MatchCase:=0, WholeWord:=0, PatternMatch:=0, SoundsLike:=0, ReplaceOne:=1, Format:=0, Wrap:=2

Rem Loop for next "3,4"

WordBasic.CharLeft 1

GoTo Loop_

Allover:

WordBasic.StartOfDocument

Rem Disable 'with pattern match'

With Selection.Find

.MatchWildcards = False

End With

End Sub

Back to list of my macros

Like some details on the programmer?