Skip to content

Instantly share code, notes, and snippets.

@touchiep
Created November 8, 2024 15:49
Show Gist options
  • Save touchiep/e537ab92ad072e4623cbe04c9ba30ca1 to your computer and use it in GitHub Desktop.
Save touchiep/e537ab92ad072e4623cbe04c9ba30ca1 to your computer and use it in GitHub Desktop.
[PowerPoint][VBA] Convert Thai number to western and convert western number to Thai.
Sub W2TH()
'สำหรับแปลงเลขฮินดูอารบิกเป็นเลขไทย
Dim i, s
Dim EngChar
Dim ThaChar
Dim EngArray As Variant
Dim ThaArray As Variant
EngChar = "1 2 3 4 5 6 7 8 9 0"
EngArray = Split(EngChar, " ")
ThaChar = "๑ ๒ ๓ ๔ ๕ ๖ ๗ ๘ ๙ ๐"
ThaArray = Split(ThaChar, " ")
s = ActiveWindow.Selection.TextRange.Text
For i = LBound(EngArray) To UBound(EngArray)
s = Replace(s, EngArray(i), ThaArray(i))
Next i
With ActiveWindow.Selection.TextRange
.Text = s
End With
End Sub
Sub TH2W()
'สำหรับแปลงเลขไทยเป็นเลขฮินดูอารบิก
Dim i, s
Dim EngChar
Dim ThaChar
Dim EngArray As Variant
Dim ThaArray As Variant
EngChar = "1 2 3 4 5 6 7 8 9 0"
EngArray = Split(EngChar, " ")
ThaChar = "๑ ๒ ๓ ๔ ๕ ๖ ๗ ๘ ๙ ๐"
ThaArray = Split(ThaChar, " ")
s = ActiveWindow.Selection.TextRange.Text
For i = LBound(ThaArray) To UBound(ThaArray)
s = Replace(s, ThaArray(i), EngArray(i))
Next i
With ActiveWindow.Selection.TextRange
.Text = s
End With
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment