|
本帖最后由 413191246se 于 2016-9-12 22:22 编辑
***简介:《人民币中文大写转阿拉伯数字》宏(v1.00_Beta),由于本人水平较低,未达到完美程度,但轻量级的中文大写金额(如10亿以下)基本比较正确,现在有些10-100亿的金额尚未解决(未解决的在附件《疑难》中),最大识别金额为壹仟亿元整!***如有需要的朋友(包括徒弟139),在你的实际工作中如果数值不超过10亿元,可以应用此宏,但建议转换后务必认真校对,以确保数据完全。
***在运行本宏的过程中,请不要操作鼠标和键盘,直到程序完成。
***怎么消除转换后的重波浪线呢?很简单,只须:编辑菜单/全选/点击工具栏上的下划线按钮两次(中间要稍等一下)即可。
测试附件:
demo 人民币中文大写转阿拉伯数字(测试附件).rar
(10.36 KB, 下载次数: 29)
- Sub 人民币中文大写转阿拉伯数字()
- Dim n As Long, i As String, j As String
- If MsgBox("阿拉伯数字是否放在大写前面?(否则后面)", vbYesNo + vbExclamation, "人民币中文大写转阿拉伯数字") = vbYes Then n = 1 Else n = 0
- ActiveDocument.Paragraphs.Last.Range.InsertAfter Text:=vbCr & "`"
- Selection.HomeKey unit:=wdStory
- Do
- Selection.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
- If Selection = "`" Then Exit Do
- Do While Selection.Characters.Last Like "[壹贰叁肆伍陆柒捌玖零亿万仟佰拾元圆角分整]"
- Selection.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
- If Selection.Characters.Last Like "[!壹贰叁肆伍陆柒捌玖零亿万仟佰拾元圆角分整]" Then
- Selection.MoveEnd unit:=wdCharacter, Count:=-1
- If Len(Selection) = 1 Then Exit Do
- Do While Selection Like "[亿万仟佰元圆角分整]*"
- Selection.MoveStart unit:=wdCharacter, Count:=1
- Loop
- Do While Selection Like "*零"
- Selection.MoveEnd unit:=wdCharacter, Count:=-1
- Loop
- If Selection Like "*仟*亿*元*" And Selection <> "壹仟亿元整" Then
- Selection.Font.Color = wdColorRed '红色
- Selection.Font.Bold = True '加粗
- Selection.Font.Underline = wdUnderlineWavyHeavy '重波浪线
- GoTo Skip
- End If
- ' Selection.Font.Bold = True '加粗
- ' Selection.Font.Color = wdColorBlue '蓝色
- Selection.Font.Underline = wdUnderlineWavyHeavy '重波浪线
- Skip:
- i = Selection.Text
- i = Replace(i, "圆", "元")
- If i Like "*[!元角分整]" Then i = i & "元整"
- If i Like "*元" Then i = i & "整"
- '
- If i Like "*佰亿零?仟万*" Then i = Replace(i, "佰亿零", "00")
- If i Like "*佰亿零?佰万*" Then i = Replace(i, "佰亿零", "000")
- If i Like "*佰亿零?拾万*" Then i = Replace(i, "佰亿零", "0000")
- If i Like "*佰亿零?万*" Then i = Replace(i, "佰亿零", "00000")
- If i Like "*佰亿零?仟*" Then i = Replace(i, "佰亿零", "000000")
- If i Like "*佰亿零?佰*" Then i = Replace(i, "佰亿零", "0000000")
- If i Like "*佰亿零?拾*" Then i = Replace(i, "佰亿零", "00000000")
- If i Like "*佰亿零*" Then i = Replace(i, "佰亿零", "000000000")
- If i Like "*拾亿零?仟万*" Then i = Replace(i, "拾亿零", "0")
- If i Like "*拾亿零?佰万*" Then i = Replace(i, "拾亿零", "00")
- If i Like "*拾亿零?拾万*" Then i = Replace(i, "拾亿零", "000")
- If i Like "*拾亿零?万*" Then i = Replace(i, "拾亿零", "0000")
- If i Like "*拾亿零?仟*" Then i = Replace(i, "拾亿零", "00000")
- If i Like "*拾亿零?佰*" Then i = Replace(i, "拾亿零", "000000")
- If i Like "*拾亿零?拾*" Then i = Replace(i, "拾亿零", "0000000")
- If i Like "*拾亿零*" Then i = Replace(i, "拾亿零", "00000000")
- If i Like "*亿零?佰万*" Then i = Replace(i, "亿零", "0")
- If i Like "*亿零?拾万*" Then i = Replace(i, "亿零", "00")
- If i Like "*亿零?万*" Then i = Replace(i, "亿零", "000")
- If i Like "*亿零?仟*" Then i = Replace(i, "亿零", "0000")
- If i Like "*亿零?佰*" Then i = Replace(i, "亿零", "00000")
- If i Like "*亿零?拾*" Then i = Replace(i, "亿零", "000000")
- If i Like "*亿零*" Then i = Replace(i, "亿零", "0000000")
- If i Like "*仟万零?仟*" Then i = Replace(i, "仟万零", "000")
- If i Like "*仟万零?佰*" Then i = Replace(i, "仟万零", "0000")
- If i Like "*仟万零?拾*" Then i = Replace(i, "仟万零", "00000")
- If i Like "*仟万零*" Then i = Replace(i, "仟万零", "000000")
- If i Like "*佰万零?仟*" Then i = Replace(i, "佰万零", "00")
- If i Like "*佰万零?佰*" Then i = Replace(i, "佰万零", "000")
- If i Like "*佰万零?拾*" Then i = Replace(i, "佰万零", "0000")
- If i Like "*佰万零*" Then i = Replace(i, "佰万零", "00000")
- If i Like "*拾万零?仟*" Then i = Replace(i, "拾万零", "0")
- If i Like "*拾万零?佰*" Then i = Replace(i, "拾万零", "00")
- If i Like "*拾万零?拾*" Then i = Replace(i, "拾万零", "000")
- If i Like "*拾万零*" Then i = Replace(i, "拾万零", "0000")
- If i Like "*万零?佰*" Then i = Replace(i, "万零", "0")
- If i Like "*万零?拾*" Then i = Replace(i, "万零", "00")
- If i Like "*万零*" Then i = Replace(i, "万零", "000")
- If i Like "*仟零?拾*" Then i = Replace(i, "仟零", "0")
- If i Like "*仟零*" Then i = Replace(i, "仟零", "00")
- If i Like "*?万亿元*" Then i = Replace(i, "万亿", "000000000000")
- If i Like "*?仟亿元*" Then i = Replace(i, "仟亿", "00000000000")
- If i Like "*?佰亿元*" Then i = Replace(i, "佰亿", "0000000000")
- If i Like "*?拾亿元*" Then i = Replace(i, "拾亿", "000000000")
- If i Like "*?亿元*" Then i = Replace(i, "亿", "00000000")
- If i Like "*?仟万元*" Then i = Replace(i, "仟万", "0000000")
- If i Like "*?佰万元*" Then i = Replace(i, "佰万", "000000")
- If i Like "*?拾万元*" Then i = Replace(i, "拾万", "00000")
- If i Like "*?万元*" Then i = Replace(i, "万", "0000")
- If i Like "*?仟元*" Then i = Replace(i, "仟", "000")
- If i Like "*?佰元*" Then i = Replace(i, "佰", "00")
- If i Like "*?拾元*" Then i = Replace(i, "拾", "0")
- i = Replace(i, "元整", "")
- If Not (i Like "*元零?分*") Then i = Replace(i, "元零", "元")
- If i Like "*元?角" Then i = Replace(i, "角", "0")
- If i Like "?角?分" Then i = "0." & i
- If i Like "?角" Then i = "0." & i & "0"
- If i Like "?分" Then i = "0.0" & i
- i = Replace(i, "壹", "1")
- i = Replace(i, "贰", "2")
- i = Replace(i, "叁", "3")
- i = Replace(i, "肆", "4")
- i = Replace(i, "伍", "5")
- i = Replace(i, "陆", "6")
- i = Replace(i, "柒", "7")
- i = Replace(i, "捌", "8")
- i = Replace(i, "玖", "9")
- i = Replace(i, "零", "0")
- i = Replace(i, "亿", "")
- i = Replace(i, "万", "")
- i = Replace(i, "仟", "")
- i = Replace(i, "佰", "")
- i = Replace(i, "拾", "")
- i = Replace(i, "元", ".")
- i = Replace(i, "角", "")
- i = Replace(i, "分", "")
- i = Replace(i, "整", "")
- j = "(¥:" & i & "元)"
- If n = 1 Then Selection.InsertBefore Text:=j Else Selection.InsertAfter Text:=j
- Exit Do
- End If
- Loop
- Selection.MoveRight unit:=wdCharacter, Count:=1
- Loop
- ActiveDocument.Paragraphs.Last.Range.Delete
- MsgBox "处理完毕!!!!!!" & vbCr & "请注意!中文大写金额最大不得超过<壹仟亿元整>,否则转换将不正确!" & vbCr & _
- "请检查文中是否有<红色/加粗/重波浪线>金额(超过限制),手动转换!" _
- & vbCr & "本宏为 v1.00 Beta 版本,数据超过10亿可能转换不正确,最大不得超过1千亿!", vbOKOnly + vbExclamation, "人民币中文大写转阿拉伯数字"
- End Sub
复制代码
|
|