|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
经测试,当小写金额为负数时,大写未能正常转,修改后就可以了:
' 试编写数字金额转中文大写的函数
' lin jin xiang 08-07-2004
Function DaXie(ByVal Num) ' 人民币中文大写函数
Application.Volatile True
Place = "分角元拾佰仟万拾佰仟亿拾佰仟万"
Dn = "壹贰叁肆伍陆柒捌玖"
D1 = "整零元零零零万零零零亿零零零万"
If Num < 0 Then FuHao = "(负)"
Num = Format(Abs(Num), "###0.00") * 100
If Num > 999999999999999# Then: DaXie = "数字超出转换范围!!": Exit Function
If Num = 0 Then: DaXie = "零元零分": Exit Function
NumA = Trim(Str(Num))
NumLen = Len(NumA)
For j = NumLen To 1 Step -1 ' 数字转换过程
Temp = Val(Mid(NumA, NumLen - j + 1, 1))
If Temp <> 0 Then ' 非零数字转换
NumC = NumC & Mid(Dn, Temp, 1) & Mid(Place, j, 1)
Else ' 数字零的转换
If Right(NumC, 1) <> "零" Then
NumC = NumC & Mid(D1, j, 1)
Else
Select Case j ' 特殊数位转换
Case 1
NumC = Left(NumC, Len(NumC) - 1) & Mid(D1, j, 1)
Case 3, 11
NumC = Left(NumC, Len(NumC) - 1) & Mid(D1, j, 1) & "零"
Case 7
If Mid(NumC, Len(NumC) - 1, 1) <> "亿" Then
NumC = Left(NumC, Len(NumC) - 1) & Mid(D1, j, 1) & "零"
End If
Case Else
End Select
End If
End If
Next
DaXie = FuHao & Trim(NumC)
End Function |
|