Function DocSoTien(ByVal SoTien As Double, Dong As String, Xu As String) As String
Dim Nguyen As Double, Le As Long
SoTien = Round(SoTien, 2)
Nguyen = Int(SoTien)
Le = (SoTien - Nguyen) * 100
DocSoTien = DocSo(Nguyen) & " " & Dong
If Le <> 0 Then
DocSoTien = DocSoTien & " v" & ChrW(224) & " " & DocSo(Le) & " " & Xu
End If
Mid(DocSoTien, 1, 1) = UCase(Mid(DocSoTien, 1, 1))
End Function
Private Function DocSo(ByVal SoTien As Double) As String
Dim MyArray As Variant
Dim Str As String
Str = Format(Abs(SoTien), "000000000000000000")
MyArray = Array("không ", "m" & ChrW(7897) & "t ", "hai ", "ba ", "b" & ChrW(7889) & "n ", "n" & ChrW(259) & "m ", "sáu ", "b" & ChrW(7843) & "y ", "tám ", "chín ", "tri" & ChrW(7879) & "u, ", "ngàn, ", "t" & ChrW(7927) & ", ", "tri" & ChrW(7879) & "u, ", "ngàn, ", "", "tr" & ChrW(259) & "m ", "m" & ChrW(432) & ChrW(417) & "i ", "không " & "m" & ChrW(432) & ChrW(417) & "i" & " không ", "không " & "m" & ChrW(432) & ChrW(417) & "i", "l" & ChrW(7867), "m" & ChrW(432) & ChrW(417) & "i" & " không", "m" & ChrW(432) & ChrW(417) & "i", "m" & ChrW(432) & ChrW(417) & "i" & " n" & ChrW(259) & "m", "m" & ChrW(432) & ChrW(417) & "i" & " l" & ChrW(259) & "m", "m" & ChrW(7897) & "t " & "m" & ChrW(432) & ChrW(417) & "i", "m" & ChrW(432) & ChrW(7901) & "i", "m" & ChrW(432) & ChrW(417) & "i" & " m" & ChrW(7897) & "t", "m" & ChrW(432) & ChrW(417) & "i" & " m" & ChrW(7889) & "t", "Âm ")
If Str = "000000000000000000" Then
DocSo = MyArray(0)
Exit Function
End If
For i = 1 To Len(Str)
If Left(Str, i) <> 0 And Mid(Str, (Int((i + 2) / 3) - 1) * 3 + 1, 3) <> 0 Then
DocSo = DocSo & MyArray(Mid(Str, i, 1)) & MyArray(-(9 + i / 3) * (i Mod 3 = 0) - (15 + i Mod 3) * (i Mod 3 <> 0))
ElseIf i = 9 And Mid(Str, 7, 3) = 0 And Left(Str, 6) <> 0 Then
DocSo = DocSo & MyArray(12)
End If
Next
DocSo = Replace(DocSo, ", " & MyArray(12), " " & MyArray(12))
DocSo = Trim(Replace(Replace(Replace(Replace(Replace(Replace(DocSo, MyArray(18), MyArray(15)), MyArray(19), MyArray(20)), MyArray(21), MyArray(22)), MyArray(23), MyArray(24)), MyArray(25), MyArray(26)), MyArray(27), MyArray(28)))
If SoTien < 0 Then
DocSo = MyArray(29) & DocSo
End If
DocSo = Replace(Replace(DocSo & ".", ",.", "."), ".", "")
End Function