How to Convert Number to Words in MS Word: A Step-by-Step Guide

How to Convert Numbers to Words in MS Word

Converting numbers to words in MS Word is a simple task that involves using a bit of VBA (Visual Basic for Applications) code. By following a few quick steps, you can transform numerical figures into text, making your documents more reader-friendly and professional.

How to Convert Numbers to Words in MS Word

This section will guide you through converting numbers to words in MS Word using VBA. By completing these steps, you’ll be able to automatically convert any number in your document to its word equivalent.

Step 1: Open MS Word

First, open your Microsoft Word application and start with a blank document.

Opening a new document ensures you have a clean slate to work with.

Step 2: Press Alt + F11

Pressing Alt + F11 will open the Visual Basic for Applications (VBA) editor.

The VBA editor is where you’ll enter the necessary code to perform the conversion.

Step 3: Insert a New Module

In the VBA editor, go to "Insert" and select "Module" from the dropdown menu.

Inserting a new module creates a space for you to input the VBA code.

Step 4: Copy and Paste VBA Code

Copy the following VBA code and paste it into the module:

Function NumberToWords(ByVal MyNumber)
    Dim Units As String
    Dim Tens As String
    Dim Hundreds As String
    Dim Temp
    Dim DecimalPlace As Integer, Count As Integer
    ReDim Place(9) As String
    Place(2) = " Thousand "
    Place(3) = " Million "
    Place(4) = " Billion "
    Place(5) = " Trillion "
    MyNumber = Trim(CStr(MyNumber))
    DecimalPlace = InStr(MyNumber, ".")
    If DecimalPlace > 0 Then
        Temp = Left(MyNumber, DecimalPlace - 1)
    Else
        Temp = MyNumber
    End If
    Count = 1
    Do While Temp  ""
        Hundreds = ""
        If Len(Temp) > 3 Then
            Hundreds = Right(Temp, 3)
            Temp = Left(Temp, Len(Temp) - 3)
        Else
            Hundreds = Temp
            Temp = ""
        End If
        If Hundreds  "" Then
            Hundreds = ConvertHundreds(Hundreds)
            Units = Place(Count) & Hundreds & Units
        End If
        Count = Count + 1
    Loop
    NumberToWords = Application.Trim(Units)
End Function

Private Function ConvertHundreds(ByVal MyNumber)
    Dim Result As String
    If Val(MyNumber) = 0 Then Exit Function
    MyNumber = Right("000" & MyNumber, 3)
    If Mid(MyNumber, 1, 1)  "0" Then
        Result = ConvertDigit(Mid(MyNumber, 1, 1)) & " Hundred "
    End If
    If Mid(MyNumber, 2, 1)  "0" Then
        Result = Result & ConvertTens(Mid(MyNumber, 2))
    Else
        Result = Result & ConvertDigit(Mid(MyNumber, 3))
    End If
    ConvertHundreds = Result
End Function

Private Function ConvertTens(ByVal MyTens)
    Dim Result As String
    Result = ""
    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
        Result = Result & ConvertDigit(Right(MyTens, 1))
    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

This code will convert numbers into words for you.

Step 5: Save and Close the VBA Editor

Save your work by clicking the save icon or going to "File" and selecting "Save". Then close the VBA editor.

Saving ensures you don’t lose the code, and closing the editor takes you back to your Word document.

Step 6: Use the Function in Your Document

To use the function, type =NumberToWords(123) in your Word document and press Enter.

Replace 123 with the number you want to convert. The result will display the number in words.

Step 7: Update Fields

If the result doesn’t display immediately, press Ctrl + A to select all text, then press F9 to update fields.

Updating fields ensures all your function results are displayed correctly.

After completing these steps, any number you specify using the NumberToWords function will be converted to its word format automatically.

Tips for Converting Numbers to Words in MS Word

  • Always save your document before adding VBA code to avoid losing data.
  • Use descriptive names for your functions to make the code easier to understand.
  • Test the function with different numbers to ensure accuracy.
  • Remember to update fields (F9) if the conversion doesn’t appear immediately.
  • If the VBA code doesn’t work, double-check for any syntax errors.

Frequently Asked Questions

How do I open the VBA editor in MS Word?

Press Alt + F11 to open the VBA editor in MS Word.

What is VBA?

VBA stands for Visual Basic for Applications and is used to automate tasks in Microsoft Office applications.

Can I use this code in Excel?

Yes, you can use similar VBA code in Excel to convert numbers to words.

What if the code doesn’t work?

Double-check for any syntax errors and ensure you’ve copied the code correctly.

Do I need to update fields every time?

Yes, pressing Ctrl + A and then F9 updates your document to reflect the latest changes.

Summary

  1. Open MS Word
  2. Press Alt + F11
  3. Insert a New Module
  4. Copy and Paste VBA Code
  5. Save and Close the VBA Editor
  6. Use the Function in Your Document
  7. Update Fields

Conclusion

Converting numbers to words in MS Word is a handy trick that can make your documents more readable and professional. Whether you’re dealing with invoices, financial reports, or any document where numbers need to be spelled out, this simple VBA code can save you a lot of time and effort.

By following the steps outlined above, you’ll be able to quickly and efficiently convert any number into words. Don’t forget to save your work and check for any errors in your code. For more advanced functionality, consider exploring additional VBA capabilities or seeking out more complex scripts.

Happy converting!