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

动态 未结 0 63
小小草
小小草 LV1 2023年9月23日 23:40 发表
以下是将数字转换为大写金额的VBA代码: ``` Sub ConvertToWords() Dim MyNumber As Currency Dim Dollars As String Dim Cents As String Dim Temp As String ' Change this value to the amount you want to convert. MyNumber = InputBox("Enter the amount in numbers:") ' Check for zero value. If MyNumber = 0 Then MsgBox "Zero dollars" Exit Sub End If ' Convert MyNumber to a string, trimming extra spaces. MyNumber = Trim(Str(MyNumber)) ' Find decimal point. Dim DecimalPlace As Integer DecimalPlace = InStr(MyNumber, ".") ' Convert cents and set MyNumber to dollar amount. If DecimalPlace > 0 Then Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)) MyNumber = Trim(Left(MyNumber, DecimalPlace - 1)) End If ' Add "dollars" to end of MyNumber. Dollars = "" Select Case Len(MyNumber) Case 1 To 3 Dollars = GetHundreds(MyNumber) Case 4 To 6 Dollars = GetThousands(Left(MyNumber, Len(MyNumber) - 3)) & " " & GetHundreds(Right(MyNumber, 3)) Case 7 To 9 Dollars = GetMillions(Left(MyNumber, Len(MyNumber) - 6)) & " " & GetThousands(Mid(MyNumber, Len(MyNumber) - 2, 3)) & " " & GetHundreds(Right(MyNumber, 3)) Case Else MsgBox "Too many digits" Exit Sub End Select ' Clean up dollars. Select Case Dollars Case "" Dollars = "No dollars" Case "One" Dollars = "One dollar" Case Else Dollars = Dollars & " dollars" End Select ' Clean up cents. Select Case Cents Case "" Cents = " and no cents" Case "One" Cents = " and one cent" Case Else Cents = " and " & Cents & " cents" End Select ' Combine dollars and cents.
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复