在word里面把数字变成大写的金额,帮我写一段vba代码实现此功能

动态 未结 0 62
小小草
小小草 LV1 2023年9月23日 23:40 发表
以下是将数字转换为大写金额的VBA代码: ``` Sub ConvertToWords() Dim MyNumber As Currency Dim Dollars As String, Cents As String Dim Temp As String, DecimalPlace As Integer Dim Count As Integer ' Change this variable to the currency you want to convert to Const CurrencyName = "Dollars" ' Set up test values MyNumber = Range("A1").Value ' Check for zero value If MyNumber = 0 Then Range("B1").Value = "Zero " & CurrencyName Exit Sub End If ' Check for negative value If MyNumber < 0 Then MyNumber = Abs(MyNumber) Temp = "Negative " End If ' Convert number to string and locate decimal place Temp = Format(MyNumber, "0.00") DecimalPlace = InStr(Temp, ".") Dollars = Left(Temp, DecimalPlace - 1) Cents = Right(Temp, 2) ' Convert dollars to words Count = 1 Do While Dollars <> "" Select Case Count Case 1 Temp = GetHundreds(Left(Dollars, 3)) If Temp <> "" Then Dollars = Right(Dollars, Len(Dollars) - 3) Else Dollars = "" If Dollars <> "" Then Temp = Temp & " Thousand " Case 2 Temp = GetHundreds(Left(Dollars, 3)) If Temp <> "" Then Dollars = Right(Dollars, Len(Dollars) - 3) Else Dollars = "" If Dollars <> "" Then Temp = Temp & " Million " Case 3 Temp = GetHundreds(Left(Dollars, 3)) If Temp <> "" Then Dollars = Right(Dollars, Len(Dollars) - 3) Else Dollars = "" If Dollars <> "" Then Temp = Temp & " Billion " End Select Range("B1").Value = Range("B1").Value & Temp Count = Count + 1 Loop ' Add currency name and cents to final result If Cents <> "" Then Range("B1").Value = Range("B1").Value & " and " & Cents & "/100
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复