|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我对Word不熟,刚才从网上现抄了一个,网址:https://baijiahao.baidu.com/s?id ... r=spider&for=pc。
Excel自定义函数,选择那组数据,运行
- Sub test()
- Dim s As Double
- s = Selection.Range
- Debug.Print NumToChar(s)
- Selection.EndKey Unit:=wdLine
- Selection.TypeParagraph
- Selection.TypeText Text:=NumToChar(s)
- End Sub
- Function NumToChar(Number As Double) As String
- Dim strNum As String
- Dim arrNum(), arrChar(), arrUnits(), arr()
- Dim k As Integer
-
- Temp = Abs(Round(Number, 2)) * 100
- strNum = CStr(Temp)
- arrChar = Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖")
- arrUnits = Array("分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟", "京")
- For i = Len(strNum) To 1 Step -1
- ReDim Preserve arr(k)
- arr(k) = Mid(strNum, i, 1)
- If arr(k) = 0 Then
- If InStr("元万亿兆", arrUnits(k)) Then
- arr(k) = arrUnits(k)
- Else
- arr(k) = "零"
- End If
- Else
- arr(k) = arrChar(arr(k)) & arrUnits(k)
- End If
- k = k + 1
- Next
- strNum = ""
- For i = UBound(arr) To LBound(arr) Step -1
- strNum = strNum & arr(i)
- Next
- If Round(Number, 0) = Number Then
- strNum = Left(strNum, InStr(strNum, "元")) & "整"
- ElseIf Round(Number, 1) = Number Then
- strNum = Left(strNum, InStr(strNum, "角")) & "整"
- End If
-
- Do While InStr(strNum, "零零") > 0
- strNum = Replace(strNum, "零零", "零")
- Loop
-
- strNum = Replace(strNum, "零兆", "兆")
- strNum = Replace(strNum, "零亿", "亿")
- strNum = Replace(strNum, "零万", "万")
- strNum = Replace(strNum, "零元", "元")
- strNum = Replace(strNum, "兆亿", "兆")
- strNum = Replace(strNum, "兆万", "兆")
- strNum = Replace(strNum, "亿万", "亿")
- If Number < 0 Then
- strNum = "负" & strNum
- ElseIf Number = 0 Then
- strNum = "零元整"
- End If
- NumToChar = strNum
- End Function
复制代码
你的数据1234567.89,运行正确。 |
评分
-
1
查看全部评分
-
|