(của bạn Nguyen Vu Loc post lên VNN1)
Public Function VND(BaoNhieu)
Dim KetQua, SoTien, Nhom, Chu, Dich, S1, S2, S3 As String
Dim I, J, ViTri As Byte, S As Double
Dim Hang, Doc, dem
If BaoNhieu = 0 Then
KetQua = "Không đồng"
Else
If Abs(BaoNhieu) >= 1E+15 Then
KetQua = "Số quá lớn"
Else
If BaoNhieu < 0 Then
KetQua = "Trừ" & Space(1)
Else
KetQua = Space(0)
End If
SoTien = Format(Abs(BaoNhieu), "##############0.00")
SoTien = Right(Space(15) & SoTien, 18)
Hang = Array("None", "trăm", "mươi", "gì ®ó")
Doc = Array("None", "ngàn tỉ", "tỉ", "triệu", "ngàn", "đồng", "xu")
dem = Array("None", "một", "hai", "ba", "bốn", "năm", "sáu", "bảy", "tám", "chín")
For I = 1 To 6
Nhom = Mid(SoTien, I * 3 - 2, 3)
If Nhom <> Space(3) Then
Select Case Nhom
Case "000"
If I = 5
Then
Chu = "đồng" & Space(1)
Else
Chu = Space(0)
End If
Case ".00"
Chu = "chẵn"
Case Else
S1 = Left(Nhom, 1)
S2 = Mid(Nhom, 2, 1)
S3 = Right(Nhom, 1)
Chu = Space(0)
Hang(3) = Doc(I)
For J = 1 To 3
Dich = Space(0)
S = Val(Mid(Nhom, J, 1))
If S > 0 Then
Dich = dem(S) & Space(1) & Hang(J) & Space(1)
End If
Select Case J
Case 2 And S = 1
Dich = "mười" & Space(1)
Case 3 And S = 0 And Nhom <> Space(2) & "0"
Dich = Hang(J) & Space(1)
Case 3 And S = 5 And S2 <> Space(1) And S2 <> "0"
Dich = "l" & Mid(Dich, 2) 'kí tự en lờ
Case 2 And S = 0 And S3 <> "0"
If (S1 >= "1" And S1 <= "9") Or (S1 = "0" And I = 4) Then
Dich = "lẻ" & Space(1)
End If
End Select
Chu = Chu & Dich
Next J
End Select
ViTri = InStr(1, Chu, "mươi một", 1)
If ViTri > 0 Then Mid(Chu, ViTri, 9) = "mươi mốt"
KetQua = KetQua & Chu
End If
Next I
End If
End If
VND = UCase(Left(KetQua, 1)) & Mid(KetQua, 2)
End Function