WEB开发网
开发学院WEB开发综合 把数字转成英文字 阅读

把数字转成英文字

 2006-02-27 11:41:33 来源:WEB开发网   
核心提示:●建立D2T巨集,并把快速键设为Shift Ctrl T,把数字转成英文字,●写入程式码:SubD2T()DimMyStrAsStringMyStr=ActiveCell.TextIfIsNumeric(MyStr)=TrueThenActiveCell.Value=""SelectCaseLen(
●建立D2T巨集,并把快速键设为Shift Ctrl T。


●写入程式码:

SubD2T()
DimMyStrAsString
MyStr=ActiveCell.Text

IfIsNumeric(MyStr)=TrueThen
ActiveCell.Value=""

SelectCaseLen(MyStr)
Case1
OneDG(MyStr)
Case2
TwoDG(MyStr)
Case3
ThreeDG(MyStr)
Case4
OneDG(Left(MyStr,1))
ActiveCell.Value=ActiveCell.Value "Thousand"
ThreeDG(Right(MyStr,3))
Case5
TwoDG(Left(MyStr,2))
ActiveCell.Value=ActiveCell.Value "Thousand"
ThreeDG(Right(MyStr,3))
Case6
ThreeDG(Left(MyStr,3))
ActiveCell.Value=ActiveCell.Value "Thousand"
ThreeDG(Right(MyStr,3))
Case7
OneDG(Left(MyStr,1))
ActiveCell.Value=ActiveCell.Value "Millon"
ThreeDG(Mid(MyStr,2,3))
ActiveCell.Value=ActiveCell.Value "Thousand"
ThreeDG(Right(MyStr,3))
Case8
TwoDG(Left(MyStr,2))
ActiveCell.Value=ActiveCell.Value "Millon"
ThreeDG(Mid(MyStr,3,3))
ActiveCell.Value=ActiveCell.Value "Thousand"
ThreeDG(Right(MyStr,3))
Case9
ThreeDG(Left(MyStr,3))
ActiveCell.Value=ActiveCell.Value "Millon"
ThreeDG(Mid(MyStr,4,3))
ActiveCell.Value=ActiveCell.Value "Thousand"
ThreeDG(Right(MyStr,3))
Case10
OneDG(Left(MyStr,1))
ActiveCell.Value=ActiveCell.Value "Billon"
ThreeDG(Mid(MyStr,2,3))
ActiveCell.Value=ActiveCell.Value "Millon"
ThreeDG(Mid(MyStr,5,3))
ActiveCell.Value=ActiveCell.Value "Thousand"
ThreeDG(Right(MyStr,3))
Case11
TwoDG(Left(MyStr,2))
ActiveCell.Value=ActiveCell.Value "Billon"
ThreeDG(Mid(MyStr,3,3))
ActiveCell.Value=ActiveCell.Value "Millon"
ThreeDG(Mid(MyStr,6,3))
ActiveCell.Value=ActiveCell.Value "Thousand"
ThreeDG(Right(MyStr,3))
CaseElse
EndSelect
EndIf
EndSub

SubOneDG(MyStrAsString)
SelectCaseMyStr
Case"0"
IfActiveCell.Value=""ThenActiveCell.Value=ActiveCell.Value "Zero"
Case"1"
ActiveCell.Value=ActiveCell.Value "One"
Case"2"
ActiveCell.Value=ActiveCell.Value "Two"
Case"3"
ActiveCell.Value=ActiveCell.Value "Three"
Case"4"
ActiveCell.Value=ActiveCell.Value "Four"
Case"5"
ActiveCell.Value=ActiveCell.Value "Five"
Case"6"
ActiveCell.Value=ActiveCell.Value "Six"
Case"7"
ActiveCell.Value=ActiveCell.Value "Seven"
Case"8"
ActiveCell.Value=ActiveCell.Value "Eight"
Case"9"
ActiveCell.Value=ActiveCell.Value "Nine"
EndSelect
EndSub

SubTwoDG(MyStrAsString)
SelectCaseMyStr
Case"10"
ActiveCell.Value=ActiveCell.Value "Ten"
Case"11"
ActiveCell.Value=ActiveCell.Value "eleven"
Case"12"
ActiveCell.Value=ActiveCell.Value "Twelve"
Case"13"
ActiveCell.Value=ActiveCell.Value "Thirteen"
Case"14"
ActiveCell.Value=ActiveCell.Value "Fourteen"
Case"15"
ActiveCell.Value=ActiveCell.Value "Fifteen"
Case"16"
ActiveCell.Value=ActiveCell.Value "Sixteen"
Case"17"
ActiveCell.Value=ActiveCell.Value "Seventeen"
Case"18"
ActiveCell.Value=ActiveCell.Value "Eighteen"
Case"19"
ActiveCell.Value=ActiveCell.Value "Nineteen"
CaseElse
SelectCaseLeft(MyStr,1)
Case"2"
ActiveCell.Value=ActiveCell.Value "Twenty"
Case"3"
ActiveCell.Value=ActiveCell.Value "Thirty"
Case"4"
ActiveCell.Value=ActiveCell.Value "Forty"
Case"5"
ActiveCell.Value=ActiveCell.Value "Fifty"
Case"6"
ActiveCell.Value=ActiveCell.Value "Sixty"
Case"7"
ActiveCell.Value=ActiveCell.Value "Seventy"
Case"8"
ActiveCell.Value=ActiveCell.Value "Eighty"
Case"9"
ActiveCell.Value=ActiveCell.Value "Ninety"
EndSelect
OneDG(Right(MyStr,1))
EndSelect

EndSub

SubThreeDG(MyStrAsString)
SelectCaseLeft(MyStr,1)
Case"1"
ActiveCell.Value=ActiveCell.Value "OneHandred"
Case"2"
ActiveCell.Value=ActiveCell.Value "TwoHandred"
Case"3"
ActiveCell.Value=ActiveCell.Value "ThreeHandred"
Case"4"
ActiveCell.Value=ActiveCell.Value "FourHandred"
Case"5"
ActiveCell.Value=ActiveCell.Value "FiveHandred"
Case"6"
ActiveCell.Value=ActiveCell.Value "SixHandred"
Case"7"
ActiveCell.Value=ActiveCell.Value "SevenHandred"
Case"8"
ActiveCell.Value=ActiveCell.Value "EightHandred"
Case"9"
ActiveCell.Value=ActiveCell.Value "NightHandred"
EndSelect
TwoDGRight(MyStr,2)
EndSub
●上面的程式码可以处理到11位数。●随意输入一个未超过11位数的数字,然后把输入游标移到该Cell里。

●一同按下Shift Ctrl T。->

Tags:数字 英文

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接