Skip to content

Instantly share code, notes, and snippets.

View touchiep's full-sized avatar

Pongsathorn Sraouthai touchiep

View GitHub Profile
@touchiep
touchiep / PhoneticsAlphabet.bas
Last active February 18, 2024 09:16
[VBA][Excel] Convert text to phonetics alphabet. Support English and Thai only.
Function Phonetics(InputWord As String, Optional EngType As String = "ICAO") As String
'Convert Words to Phonetic Alphabet
'Phonetics version 1.0 by Pongsathorn Sraouthai
'Support English and Thai only
'EngType:
'ICAO = ICAO phonetics alphabet
'animal = animal phonetics alphabet
'fruit = fruit phonetics alphabet
'baby = baby phonetics alphabet
'police = Law Enforcement phonetics alphabet
@touchiep
touchiep / EngTime.bas
Last active February 18, 2024 09:17
[VBA][Excel] EnglishTime Spelling time to English
Function EnglishTime(InTime, Optional Formal As Integer = 1)
'Convert Time to English Text
'Formal
'1 = Formal
'2 = Informal
'3 = Military
Dim tInput, ThH, ThM, ThS
Select Case VarType(InTime)
Case vbDate
@touchiep
touchiep / ThaiTime.bas
Last active June 27, 2024 05:54
[VBA][Excel] ThaiTime แปลงเวลาเป็นคำพูดบอกเวลาภาษาไทย
Public Function ThaiTime(InTime, Optional TimeType As Integer = 1, Optional CType As Integer = 0)
'Version 4.0
'แปลงเลขเวลาเป็นคำอ่าน
'TimeType รองรับได้ 6 แบบ
'1 ระบบ 24 ชั่วโมงแบบราชการ
'2 ระบบ 6 ชั่วโมงแบบ 2490
'3 ระบบ 6 ชั่วโมงแบบสมียใหม่ 2535
'4 ระบบ 24 ชั่วโมงแบบทหาร
'5 ระบบ 8 ยาม แบบอยุธยา 2076
'6 ระบบ 8 ยาม แบบรัตนโกสินทร์ 2443
@touchiep
touchiep / NumberToWords.bas
Last active February 18, 2024 09:21
[VBA][Excel] Convert Number to Words in many languages base on Thai coding. Language supports in this code: Thai, Lao, Japanese, Korean, Chinese, Burmese, Khmer and Vietnamese.
Function W2U(iText As String)
'Convert Words to unicode number of character
Dim N, AllChar
For N = Len(iText) To 1 Step -1
AllChar = AscW(Mid(iText, N, 1)) & " " & AllChar
Next
W2U = AllChar
End Function
Function U2W(iCode) As String
@touchiep
touchiep / LannaLunarDate.bas
Last active February 18, 2024 09:18
[VBA][Excel] สูตรสำหรับแปลงวันที่ปกติเป็นวันที่ทางจันทรคติล้านนา สำหรับใช้กับ Excel
Public Function LNLDate(iDate As Date, Optional DispNumber As Integer = 0, Optional Zodiac As Integer = 0, Optional Era As Integer = 0, Optional DhammaDay As Boolean = False, Optional NumberOnly As Boolean = False)
'LNLDate = Lanna Lunar Date สำหรับแสดงผลวันที่แบบจันทรคติล้านนา
'แปลงวันที่แบบสุริยคติให้เป็นจันทรคติ
'Copyright 2022 and later by Pongsathorn Sraouthai
'Version 2.0 Optimized for faster calculation
'Inspired by Loy's calculation
'ตัวแปร
'iDate = วันที่ ที่ใช้อ้างอิง
'DispNumber = แสดงผลตัวเลข 0 เลขอารบิก 1 เลขไทย 2 เลขโหราล้านนา
@touchiep
touchiep / ThaiLunarDateCalc.bas
Last active February 18, 2024 09:19
[VBA][OpenOffice][LibraOffice] สูตรสำหรับแปลงวันที่ปกติ ให้เป็นจันทรคติไทย สำหรับใช้กับ OpenOffice หรือ LibreOffice
Option Explicit
Private Function XLMod(a, b)
' This attempts to mimic the Excel MOD function
XLMod = a - b * Int(a / b)
End Function
Function AthikaMas(iYear As Integer) As Boolean
'AthikaMas calculation
'Return True if the specified year is AthikaMas.
@touchiep
touchiep / ThaiLunarDateExcel.bas
Last active March 7, 2025 04:36
[VBA][Excel] สูตรสำหรับแปลงวันที่ปกติ (สุริยคติ) เป็น จันทรคติแบบไทย รวมถึงสูตรที่มีไว้สำหรับตรวจสอบ ปีอธิกมาส ปีอธิกวาร และ ปีอธิกสุรทิน
Option Explicit
Private Function XLMod(a, b)
'สำหรับใช้แทน mod ของ vba เนื่องจาก mod operator ของ vba ไม่รองรับเลขทศนิยม
XLMod = a - b * Int(a / b)
End Function
Function AthikaMas(iYear As Integer) As Boolean
'สูตรสำหรับคำนวณปีอธิกมาส
'Return True if the specified year is AthikaMas.
@touchiep
touchiep / ETCorrectionOutlook.bas
Last active February 18, 2024 11:07
[VBA][Outlook] สำหรับใช้เพื่อแก้ไขข้อความที่พิมพ์ผิดภาษาในหน้าจอแก้ไขอีเมล Outlook โดยจะแก้ไขจากอังกฤษเป็นไทยตรงส่วนข้อความที่เลือกไว้
Sub ETCorrection()
'For convert miss spelling in keyboard language from English to Thai (Spelling Thai in English Keyboard)
'by Pongsathorn Sraouthai
Dim i, s
Dim EngChar
Dim ThaChar
Dim EngArray As Variant
Dim ThaArray As Variant
Dim msg As Outlook.MailItem
@touchiep
touchiep / ETCorrection.bas
Last active February 18, 2024 09:22
[VBA]Excel]สำหรับใช้เพื่อแก้ไขข้อความในเซลล์ให้เป็นภาษาที่ถูกต้อง เวลาที่เราพิมพ์ผิดภาษา ใช้ใน Excel โดยจะแก้ไขตรงเซลล์ที่เลือกไว้
Function ETConv(iText As String)
'For convert miss spelling in keyboard language from English to Thai (Spelling Thai in English Keyboard)
'English Keyboard
Dim e1 '1st row
'Thai Kedmanee Keyboard
Dim t1 '1st row
Dim eArray As Variant
Dim tArray As Variant
Dim i
@touchiep
touchiep / ETCorrectionWord.bas
Last active February 18, 2024 09:23
[VBA][Word] สำหรับใช้เพื่อแก้ภาษาอังกฤษเป็นภาษาไทยเวลาที่พิมพ์ผิดภาษา สำหรับใช้ใน Word
Sub ETCorrection()
'For correction miss spelling from English to Thai.
Dim i
Dim EngChar
Dim ThaChar
Dim EngArray As Variant
Dim ThaArray As Variant
EngChar = "1 2 3 4 5 6 7 8 9 0 - = ! @ # $ % ^ & * ( ) _ + q w e r t y u i o p [ ] \ Q W E R T Y U I O P { } | a s d f g h j k l ; ' A S D F G H J K L : "" z x c v b n m , . / Z X C V B N M < > ?"
EngArray = Split(EngChar, " ")