Spell Out Currency

Home Up Odds & Ends Photo Gallery Search Contact Me

 

 

The information in this website is provided without risk or obligation and free of charge.  However, if you have benefitted from my efforts here and would like to make a contribution to help me continue and maintain this work then any donation will be greatly appreciated. Please click the adjacent button to access PayPal.  Thank you.
 

Microsoft Word users sometimes ask how to spell out a currency value.  Take the example below:

   
The simplest method is using a field.  The currency value that is spelled out in this fanciful check draft was created with a REF field and formatting switches.   The field code is displayed below:
   
The numeric currency field is a standard text form field (Type: Number)  bookmarked "Amount" and set to calculate on exit.   The calculate on exit setting updates the reference field when the users exits the form field.

Tip:  To display the Form Field Options dialog, unprotect the form and double-click the form field.

 

 
Unfortunately there is a limit to the size numeral that \* DollarText will format.  The limit is
$100,000.00.

What if some munificent Word user wished to contribute $1,000,000.00 or more to support my budding website??!

 I am prepared to oblige. 

Fellow Word MVP Doug Robbins and I have collaborated and put together some VBA code to spell out currency values as large $9,999,999,999.00.  That's enough to cover the burgeoning U.S. National Debt with plenty left over for me and Doug.

The code for this process is rather complex and involves several called functions.  To use this method:
  • Copy all of the code provided below to your macro project.
  • Create a text form field (Type: Number) bookmarked NumberAmount.  Shown below on left.
  • Create a text form field bookmarked TextAmount.  Shown below on right.
  • Set the routine "NumToText" to run on exit from the NumberAmount form field as shown.
  • Disable fill-in (uncheck Fill-in enabled) in the form field TextAmount.

 

Option Explicit

 

Sub NumToText()
Dim MyNumber

MyNumber = ActiveDocument.FormFields("NumberAmount").Result
If IsNumeric(MyNumber) And Val(MyNumber) < "10000000000000" Then
    ActiveDocument.FormFields("TextAmount").Result = _
    ConvertCurrencyToEnglish(ByVal MyNumber)
Else
    ActiveDocument.FormFields("TextAmount").Result = "Exceeds value limit"
End If
End Sub

Function ConvertCurrencyToEnglish(ByVal MyNumber)
Dim Temp
Dim Dollars, Cents
Dim DecimalPlace, Count

ReDim Place(9) As String
Place(2) = "thousand "
Place(3) = "million "
Place(4) = "billion "
Place(5) = "trillion "

MyNumber = Trim(Str(MyNumber))

DecimalPlace = InStr(MyNumber, ".")
If DecimalPlace > 0 Then
    Temp = Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
    Cents = ConvertTens(MyNumber, Temp)
    MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
Count = 1
Do While MyNumber <> ""
  
 'convert last 3 digits to dollars
    Temp = ConvertHundreds(Right(MyNumber, 3))
    If Temp <> "" Then Dollars = Temp & Place(Count) & Dollars
        If Len(MyNumber) > 3 Then
          
 'remove last 3 converted digits
            MyNumber = Left(MyNumber, Len(MyNumber) - 3)
        Else
            MyNumber = ""
        End If
    Count = Count + 1
Loop
'clean up dollars
Select Case Dollars
    Case ""
        Dollars = ""
    Case "One "
        Dollars = "One Dollar"
    Case Else
        Dollars = Dollars & "Dollars"
    End Select
'clean up cents
If Dollars = "" Then
    Select Case Cents
        Case ""
            Cents = ""
        Case "One "
            Cents = "One Cent"
        Case Else
            Cents = Cents & "Cents"
    End Select
Else
    Select Case Cents
        Case ""
            Cents = ""
        Case "One"
            Cents = " And One Cent"
        Case "One "
            Cents = " And One Cent"
        Case Else
            Cents = " And " & Cents & "Cents"
    End Select
End If
If Dollars = "" And Cents = "" Then
    ConvertCurrencyToEnglish = "Zero"
Else
    Temp = Dollars & Cents
    Temp = UCase(Left(Temp, 1)) & _
    LCase(Mid(Temp, 2, Len(Temp) - 1))
    ConvertCurrencyToEnglish = Temp
End If
End Function
 

Private Function ConvertHundreds(ByVal MyNumber)
Dim Result As String

If Val(MyNumber) = 0 Then Exit Function
'append leading zeros to number
MyNumber = Right("000" & MyNumber, 3)
'do we have hundreds place digit to convert?
If Left(MyNumber, 1) <> "0" Then
    Result = ConvertDigit(Left(MyNumber, 1)) & "hundred "
End If
'do we have tens place digit to convert?
If Mid(MyNumber, 2, 1) <> "0" Then
    Result = Result & ConvertTens(MyNumber, Mid(MyNumber, 2))
Else
  
 'if not, then convert the ones place digit
    Result = Result & ConvertDigit(Mid(MyNumber, 3))
End If
ConvertHundreds = Trim(Result) & " "
End Function
 

Private Function ConvertTens(ByVal MyNumber, ByVal MyTens)
Dim Result As String
'is value between 10 and 19?
If Val(Left(MyTens, 1)) = 1 Then
    Select Case Val(MyTens)
        Case 10: Result = "Ten "
        Case 11: Result = "Eleven "
        Case 12: Result = "Twelve "
        Case 13: Result = "Thirteen "
        Case 14: Result = "Fourteen "
        Case 15: Result = "Fifteen "
        Case 16: Result = "Sixteen "
        Case 17: Result = "Seventeen "
        Case 18: Result = "Eighteen "
        Case 19: Result = "Nineteen "
        Case Else
    End Select
Else
    Select Case Val(Left(MyTens, 1))
        Case 2: Result = "Twenty "
        Case 3: Result = "Thirty "
        Case 4: Result = "Forty "
        Case 5: Result = "Fifty "
        Case 6: Result = "Sixty "
        Case 7: Result = "Seventy "
        Case 8: Result = "Eighty "
        Case 9: Result = "Ninety "
       Case Else
    End Select
   
'convert ones place digit
     If Result <> "" Then
         If Mid(MyNumber, 3, 1) <> "0" Or Right(MyTens, 1) <> "0" Then
            Result = Left(Result, Len(Result) - 1) & "-" _
            & ConvertDigit(Right(MyTens, 1))
         End If
     Else
        Result = Result & ConvertDigit(Right(MyTens, 1))
    End If
End If
ConvertTens = Result
End Function
 

Private Function ConvertDigit(ByVal MyDigit)
Select Case Val(MyDigit)
    Case 1: ConvertDigit = "One "
    Case 2: ConvertDigit = "Two "
    Case 3: ConvertDigit = "Three "
    Case 4: ConvertDigit = "Four "
    Case 5: ConvertDigit = "Five "
    Case 6: ConvertDigit = "Six "
    Case 7: ConvertDigit = "Seven "
    Case 8: ConvertDigit = "Eight "
    Case 9: ConvertDigit = "Nine "
    Case Else: ConvertDigit = ""
End Select
End Function

 
Need help applying macros?  See fellow MVP Graham Mayor's  Guide for Installing Macros
You will notice in the example above  that currency value including dollars and cents is spelled out completely.  If you prefer the abbreviated display that the \* DollarText formatting switch provides shown again below, you can use a slightly modified code provided here in zip format here:

Spell Out Currency (DollarTextFormat)

 

 

Looking for something else?

Google