O
Opinicus
I've written the following macro to convert numbers in
Turkish style to English style:
<quote>
Sub TRENumber()
'
' TRENumber Macro
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ","
.Replacement.Text = "|"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "."
.Replacement.Text = ","
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "|"
.Replacement.Text = ","
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
</quote>
It's pretty straightforward. First it converts all "," to
"|"; then all "." to ","; then all "|" to ".".
A number like 1.234.567,89 (Turkish style) end up as
"1,234,567.89" (English style).
The trouble is that Replace:=wdReplaceAll is a global
command so *all* the commas and periods in the document get
exchanged for one another. This is not good. I only want the
macro to work on the text that I've highlighted.
How do I do this?
TIA.
Turkish style to English style:
<quote>
Sub TRENumber()
'
' TRENumber Macro
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ","
.Replacement.Text = "|"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "."
.Replacement.Text = ","
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "|"
.Replacement.Text = ","
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
</quote>
It's pretty straightforward. First it converts all "," to
"|"; then all "." to ","; then all "|" to ".".
A number like 1.234.567,89 (Turkish style) end up as
"1,234,567.89" (English style).
The trouble is that Replace:=wdReplaceAll is a global
command so *all* the commas and periods in the document get
exchanged for one another. This is not good. I only want the
macro to work on the text that I've highlighted.
How do I do this?
TIA.