Skip to content

Instantly share code, notes, and snippets.

View touchiep's full-sized avatar

Pongsathorn Sraouthai touchiep

View GitHub Profile
@touchiep
touchiep / NumberConverterWord.bas
Last active February 18, 2024 11:06
[VBA][Word] Code สำหรับแปลงเลขอารบิกเป็นไทย หรือแปลงเลขไทยเป็นอารบิก สำหรับใช้กับ Microsoft Word รวมถึงการตั้งค่าฟอนต์ TH SarabunPSK และ TH Sarabun New เป็นฟอนต์พื้นฐาน
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", _
@touchiep
touchiep / NumberConverterExcel.bas
Last active December 12, 2023 10:46
แปลงเลขอารบิกเป็นไทย หรือ แปลงเลขไทยเป็นอารบิก สำหรับ Microsoft Excel
Sub W2THConvert()
'Numeral converter 1.0
'copyright 2022 Pongsathorn Sraouthai
'for convert western numeral to Thai numeral or Thai numeral to western numeral.
Dim r As Range
Dim c As Range
Dim cdata
Dim copt
Dim cdp
Dim LangID, LangUI(6)
@touchiep
touchiep / GetCRCModule.bas
Last active December 12, 2023 10:46
CRC Encoding VBA code for use with PromptPayQR
Option Explicit
Public Function Crc6(b() As Byte) As Long
Dim i As Long, crc As Long: Static crcTab(0 To 255) As Long
If crcTab(1) = 0 Then CreateLookupTable crcTab, 6, True, &H6B&
crc = 63
For i = LBound(b) To UBound(b)
crc = crcTab((crc Xor b(i)) And &HFF&) Xor (crc \ 256)
Next i
@touchiep
touchiep / PromptPayQRmodule.bas
Last active May 16, 2024 10:22
VBA Code สำหรับสร้างรหัสพร้อมเพย์จากหมายเลขพร้อมเพย์ เพื่อใช้กับ QR Code
Function PromptPayQR(PromptPayID As String, Optional BahtValue As Double = 0#, Optional OneTime As Boolean = False)
'PromptPay QR code Generator By Pongsathorn Sraouthai BE 2566 (V 2.0)
'This will convert text to encode to QR code for use to generate QR 2D Barcode
'Using PROMPTPAYQR(PromptPayID,BahtValue,OneTime)
'PromptPayID = PromptPay ID (Mobile Phone number (10 digit) or Thai ID number (13 digit) or E-Wallet Number (15 digit))
'BahtValue = amount of money
'Onetime = True or False (Default is False)
'More information https://www.blognone.com/node/95133
Dim CRC16Calc
@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, " ")
@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 / 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 / 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 / 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 / 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 เลขโหราล้านนา