Last active
February 18, 2024 11:06
-
-
Save touchiep/b400489494e7d0437c2ef4974233ab43 to your computer and use it in GitHub Desktop.
[VBA][Word] Code สำหรับแปลงเลขอารบิกเป็นไทย หรือแปลงเลขไทยเป็นอารบิก สำหรับใช้กับ Microsoft Word รวมถึงการตั้งค่าฟอนต์ TH SarabunPSK และ TH Sarabun New เป็นฟอนต์พื้นฐาน
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function TH2W(strInput As String) As String | |
'Convert Thai numeral to Western numeral | |
Dim numberArray | |
numberArray = Array(ChrW(3664), "0", _ | |
ChrW(3665), "1", _ | |
ChrW(3666), "2", _ | |
ChrW(3667), "3", _ | |
ChrW(3668), "4", _ | |
ChrW(3669), "5", _ | |
ChrW(3670), "6", _ | |
ChrW(3671), "7", _ | |
ChrW(3672), "8", _ | |
ChrW(3673), "9") | |
Dim i As Long | |
TH2W = strInput | |
For i = 0 To 18 Step 2 | |
TH2W = Replace(TH2W, numberArray(i), numberArray(i + 1)) | |
Next i | |
End Function | |
Function W2TH(strInput As String) As String | |
'Convert Western numeral to Thai numeral | |
Dim numberArray | |
numberArray = Array("0", ChrW(3664), _ | |
"1", ChrW(3665), _ | |
"2", ChrW(3666), _ | |
"3", ChrW(3667), _ | |
"4", ChrW(3668), _ | |
"5", ChrW(3669), _ | |
"6", ChrW(3670), _ | |
"7", ChrW(3671), _ | |
"8", ChrW(3672), _ | |
"9", ChrW(3673)) | |
Dim i As Long | |
W2TH = strInput | |
For i = 0 To 18 Step 2 | |
W2TH = Replace(W2TH, numberArray(i), numberArray(i + 1)) | |
Next i | |
End Function | |
Sub ConvertWesterntoThai() | |
'สำหรับแปลงเลขอารบิกเป็นเลขไทยทั้งเอกสาร | |
For i = 0 To 9 | |
Selection.Find.ClearFormatting | |
Selection.Find.Replacement.ClearFormatting | |
With Selection.Find | |
.Text = i | |
.Replacement.Text = W2TH(CStr(i)) | |
.Forward = True | |
.Wrap = wdFindContinue | |
.Format = False | |
.MatchCase = False | |
.MatchWholeWord = False | |
.MatchKashida = False | |
.MatchDiacritics = False | |
.MatchAlefHamza = False | |
.MatchControl = False | |
.MatchAllWordForms = False | |
.MatchSoundsLike = False | |
.MatchWildcards = False | |
End With | |
Selection.Find.Execute Replace:=wdReplaceAll | |
Next i | |
End Sub | |
Sub ConvertThaitoWestern() | |
'สำหรับแปลงเลขไทยเป็นอารบิกทั้งเอกสาร | |
For i = 0 To 9 | |
Selection.Find.ClearFormatting | |
Selection.Find.Replacement.ClearFormatting | |
With Selection.Find | |
.Text = W2TH(CStr(i)) | |
.Replacement.Text = TH2W(CStr(i)) | |
.Forward = True | |
.Wrap = wdFindContinue | |
.Format = False | |
.MatchCase = False | |
.MatchWholeWord = False | |
.MatchKashida = False | |
.MatchDiacritics = False | |
.MatchAlefHamza = False | |
.MatchControl = False | |
.MatchAllWordForms = False | |
.MatchSoundsLike = False | |
.MatchWildcards = False | |
End With | |
Selection.Find.Execute Replace:=wdReplaceAll | |
Next i | |
End Sub | |
Sub ConvertListtoThai() | |
' สำหรับแปลงลำดับเลขเป็นเลขไทย | |
' | |
' | |
With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1) | |
.NumberStyle = wdListNumberStyleThaiArabic | |
End With | |
ListGalleries(wdNumberGallery).ListTemplates(1).Name = "" | |
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _ | |
ListGalleries(wdNumberGallery).ListTemplates(1), ContinuePreviousList:= _ | |
True, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _ | |
wdWord10ListBehavior | |
End Sub | |
Sub ConvertListToWestern() | |
' สำหรับแปลงลำดับเลขเป็นเลขอารบิก | |
' | |
' | |
With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1) | |
.NumberStyle = wdListNumberStyleArabic | |
End With | |
ListGalleries(wdNumberGallery).ListTemplates(1).Name = "" | |
Selection.Range.ListFormat.ApplyListTemplateWithLevel ListTemplate:= _ | |
ListGalleries(wdNumberGallery).ListTemplates(1), ContinuePreviousList:= _ | |
True, ApplyTo:=wdListApplyToWholeList, DefaultListBehavior:= _ | |
wdWord10ListBehavior | |
End Sub | |
Sub SetDefaultStyleTHSarabunNewThaiUI() | |
' ตั้งค่าแบบอักษรเริ่มต้น TH Sarabun New สำหรับทุกสไตล์ สำหรับเมนูไทย | |
With ActiveDocument.Styles("ปกติ").Font | |
.Name = "TH Sarabun New" | |
.Size = 16 | |
.Bold = False | |
.Italic = False | |
.Underline = wdUnderlineNone | |
.UnderlineColor = wdColorAutomatic | |
.StrikeThrough = False | |
.DoubleStrikeThrough = False | |
.Outline = False | |
.Emboss = False | |
.Shadow = False | |
.Hidden = False | |
.SmallCaps = False | |
.AllCaps = False | |
.Color = wdColorAutomatic | |
.Engrave = False | |
.Superscript = False | |
.Subscript = False | |
.Scaling = 100 | |
.Kerning = 0 | |
.Animation = wdAnimationNone | |
.SizeBi = 16 | |
.NameBi = "TH Sarabun New" | |
.BoldBi = False | |
.ItalicBi = False | |
.Ligatures = wdLigaturesNone | |
.NumberSpacing = wdNumberSpacingDefault | |
.NumberForm = wdNumberFormDefault | |
.StylisticSet = wdStylisticSetDefault | |
.ContextualAlternates = 0 | |
End With | |
With ActiveDocument.Styles("ปกติ") | |
.AutomaticallyUpdate = False | |
.BaseStyle = "" | |
.NextParagraphStyle = "ปกติ" | |
End With | |
End Sub | |
Sub SetDefaultStyleTHSarabunPSKThaiUI() | |
' ตั้งค่าแบบอักษรเริ่มต้น TH SarabunPSK สำหรับทุกสไตล์ สำหรับเมนูไทย | |
With ActiveDocument.Styles("ปกติ").Font | |
.Name = "TH SarabunPSK" | |
.Size = 16 | |
.Bold = False | |
.Italic = False | |
.Underline = wdUnderlineNone | |
.UnderlineColor = wdColorAutomatic | |
.StrikeThrough = False | |
.DoubleStrikeThrough = False | |
.Outline = False | |
.Emboss = False | |
.Shadow = False | |
.Hidden = False | |
.SmallCaps = False | |
.AllCaps = False | |
.Color = wdColorAutomatic | |
.Engrave = False | |
.Superscript = False | |
.Subscript = False | |
.Scaling = 100 | |
.Kerning = 0 | |
.Animation = wdAnimationNone | |
.SizeBi = 16 | |
.NameBi = "TH SarabunPSK" | |
.BoldBi = False | |
.ItalicBi = False | |
.Ligatures = wdLigaturesNone | |
.NumberSpacing = wdNumberSpacingDefault | |
.NumberForm = wdNumberFormDefault | |
.StylisticSet = wdStylisticSetDefault | |
.ContextualAlternates = 0 | |
End With | |
With ActiveDocument.Styles("ปกติ") | |
.AutomaticallyUpdate = False | |
.BaseStyle = "" | |
.NextParagraphStyle = "ปกติ" | |
End With | |
End Sub | |
Sub SetDefaultStyleTHSarabunNewEngUI() | |
' ตั้งค่าแบบอักษรเริ่มต้น TH Sarabun New สำหรับทุกสไตล์ สำหรับเมนูอังกฤษ | |
With ActiveDocument.Styles("Normal").Font | |
.Name = "TH Sarabun New" | |
.Size = 16 | |
.Bold = False | |
.Italic = False | |
.Underline = wdUnderlineNone | |
.UnderlineColor = wdColorAutomatic | |
.StrikeThrough = False | |
.DoubleStrikeThrough = False | |
.Outline = False | |
.Emboss = False | |
.Shadow = False | |
.Hidden = False | |
.SmallCaps = False | |
.AllCaps = False | |
.Color = wdColorAutomatic | |
.Engrave = False | |
.Superscript = False | |
.Subscript = False | |
.Scaling = 100 | |
.Kerning = 0 | |
.Animation = wdAnimationNone | |
.SizeBi = 16 | |
.NameBi = "TH Sarabun New" | |
.BoldBi = False | |
.ItalicBi = False | |
.Ligatures = wdLigaturesNone | |
.NumberSpacing = wdNumberSpacingDefault | |
.NumberForm = wdNumberFormDefault | |
.StylisticSet = wdStylisticSetDefault | |
.ContextualAlternates = 0 | |
End With | |
With ActiveDocument.Styles("Normal") | |
.AutomaticallyUpdate = False | |
.BaseStyle = "" | |
.NextParagraphStyle = "Normal" | |
End With | |
End Sub | |
Sub SetDefaultStyleTHSarabunPSKEngUI() | |
' ตั้งค่าแบบอักษรเริ่มต้น TH SarabunPSK สำหรับทุกสไตล์ สำหรับเมนูอังกฤษ | |
With ActiveDocument.Styles("Normal").Font | |
.Name = "TH SarabunPSK" | |
.Size = 16 | |
.Bold = False | |
.Italic = False | |
.Underline = wdUnderlineNone | |
.UnderlineColor = wdColorAutomatic | |
.StrikeThrough = False | |
.DoubleStrikeThrough = False | |
.Outline = False | |
.Emboss = False | |
.Shadow = False | |
.Hidden = False | |
.SmallCaps = False | |
.AllCaps = False | |
.Color = wdColorAutomatic | |
.Engrave = False | |
.Superscript = False | |
.Subscript = False | |
.Scaling = 100 | |
.Kerning = 0 | |
.Animation = wdAnimationNone | |
.SizeBi = 16 | |
.NameBi = "TH SarabunPSK" | |
.BoldBi = False | |
.ItalicBi = False | |
.Ligatures = wdLigaturesNone | |
.NumberSpacing = wdNumberSpacingDefault | |
.NumberForm = wdNumberFormDefault | |
.StylisticSet = wdStylisticSetDefault | |
.ContextualAlternates = 0 | |
End With | |
With ActiveDocument.Styles("Normal") | |
.AutomaticallyUpdate = False | |
.BaseStyle = "" | |
.NextParagraphStyle = "Normal" | |
End With | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment