Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Converting Numbers to Text.

Converting Numbers to Text

by Allen Wyatt
(last updated September 2, 2016)

13

There are times when you need to spell numbers out. For instance, you may want to spell out "1234" as "one thousand two hundred thirty-four." Word has no built-in function that will do the conversion for you, so you are left to create a macro that will handle the conversion.

The following macro, BigCardText, will convert any number between 0 and 999,999,999. To use it, simply place the insertion point either within the number you want to convert or just to the right of the number (if it is a single digit).

Sub BigCardText()
    Dim sDigits As String
    Dim sBigStuff As String

    sBigStuff = ""

    ' Select the full number in which the insertion point is located
    Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdMove
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend

    ' Store the digits in a variable
    sDigits = Trim(Selection.Text)

    If Val(sDigits) > 999999 Then
        If Val(sDigits) <= 999999999 Then
            sBigStuff = Trim(Int(Str(Val(sDigits) / 1000000)))
            ' Create a field containing the big digits and
            ' the cardtext format flag
            Selection.Fields.Add Range:=Selection.Range, _
              Type:=wdFieldEmpty, Text:="= " + sBigStuff + " \* CardText", _
              PreserveFormatting:=True

            ' Select the field and copy it
            Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
            sBigStuff = Selection.Text & " million "
            sDigits = Right(sDigits, 6)
        End If
    End If
    If Val(sDigits) <= 999999 Then
        ' Create a field containing the digits and the cardtext format flag
        Selection.Fields.Add Range:=Selection.Range, _
          Type:=wdFieldEmpty, Text:="= " + sDigits + " \* CardText", _
          PreserveFormatting:=True

        ' Select the field and copy it
        Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
        sDigits = sBigStuff & Selection.Text

        ' Now put the words in the document
        Selection.TypeText Text:=sDigits
        Selection.TypeText Text:=" "
    Else
        MsgBox "Number too large", vbOKOnly
    End If
End Sub

When using the macro, make sure that the number you are converting does not contain extraneous information, such as dollar signs or commas. When you run BigCardText, the macro checks to see if the selected number is over one million. If it is, it first works on the portion above one million, converting it to words. Then, the value below one million is converted. The final, full wording is put together and pasted back into the document, ready for use.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (7755) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Converting Numbers to Text.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Combinations for Members in Meetings

Got a large group of people listed in a worksheet and you want to make sure that each person has met with every other person ...

Discover More

Easily Changing Print Order

You can change the order in which pages are printed (normal or reversed) using the Print dialog box. What if you want a way ...

Discover More

Modifying Windows Startup Services

Windows takes advantage of many different operating system components called services. Most of the Windows services are ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Displaying the Navigation Pane when Opening a Document

The Navigation pane can be a big help in moving around a document. If you want to make sure it is always displayed for your ...

Discover More

Repaginating Your Document in a Macro

When processing a document with a macro, you may need to have the macro repaginate the text. It's easy to do using the ...

Discover More

Understanding the While...Wend Structure

One of the basic programming structures used in VBA is the While ... Wend structure. This structure helps to make the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 4?

2016-11-27 14:09:11

Jack

How do Iuse this for other language? like hebrew?


2016-09-03 08:29:13

Kevin

Joan,

You need to cut 'n paste the code into the VBA editor within Word. See the following article to get you started.

http://visualbasic.about.com/od/learnofficevbnet/a/office2007vba.htm


2016-09-02 07:21:10

Joan

Allen, this macro for converting numbers to text would be very helpful for me. However, I've never tried one of your suggested macros. How do I take the information you gave and create a macro?
Thanks, Joan.


2015-06-17 05:39:15

Ken Endacott

What exactly happened when you tried to run it?

In the VBA editor place the cursor inside the macro and press F8 successively to step through the macro. You should get an idea of what is happening.


2015-06-16 09:16:03

jagu

Dear Sir,

I paste code in word file (.docm)and enable macro but could not function,
could you kindly suggest me.

Thank you for great support.

Jagu


2015-03-26 06:20:38

Ken Endacott

Converting text to numbers, for example 'One hundred million two thousand three hundred and forty-five' to 100,002,345

Sub TextToNumbers()
Dim NT() As Variant
Dim NB As Variant
Dim N As Long
Dim ns As String
Dim R As Range
Dim k As Long
Dim L As Long
Dim LL As Long
Dim LLL As Long
Dim s As String
Dim ss As String
Dim sss As String
Dim j As Long
Dim m As Long
Dim mm As Long
Dim mmm As Long
Dim gA() As Long
Dim gB() As Long
Dim isThousandsComma As Boolean

Dim wCount As Long
NT = Array("AND", "-", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", _
"ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN", _
"TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY", _
"HUNDRED", "THOUSAND", "MILLION", "$%$%")
NB = Array(0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, _
11, 12, 13, 14, 15, 16, 17, 18, 19, _
20, 30, 40, 50, 60, 70, 80, 90, _
100, 1000, 1000000, 0)

isThousandsComma = True 'False for no commas

Set R = Selection.Range
s = R.Text
If Right(s, 1) = Chr(13) Then R.MoveEnd Unit:=wdCharacter, Count:=-1
s = R.Text
If Right(s, 1) = "." Then R.MoveEnd Unit:=wdCharacter, Count:=-1

If R.Paragraphs.Count > 1 Then
MsgBox "Selection cannot span paragraphs"
Exit Sub
End If
If Trim(R.Text) = "" Then
MsgBox "Selection does not include a word"
Exit Sub
End If

wCount = R.Words.Count
ReDim gA(wCount + 1)
ReDim gB(wCount + 1)

N = 0
ns = ""

For k = 1 To R.Words.Count
s = UCase(Trim(R.Words(k)))
If s = Chr(13) Or s = "" Then
gB(k) = 1
gA(k) = 0
GoTo FF2
End If
For m = 0 To UBound(NT) - 1
If s = NT(m) Then GoTo FF
Next m
MsgBox "The word " & """" & R.Words(k) & """" & " is non numeric"
Exit Sub
FF:
gA(k) = NB(m)
If m > UBound(NT) - 5 Then
gB(k) = 2
Else
gB(k) = 1
End If
FF2:
Next k

wCount = removeZeros(gA(), gB(), wCount)

For k = 1 To wCount - 1
If gB(k) = 1 And gB(k + 1) = 1 Then
gA(k + 1) = gA(k + 1) + gA(k)
gA(k) = 0
End If
Next k
wCount = removeZeros(gA(), gB(), wCount)

m = 1
Do
m = m + 1
Loop Until m > wCount Or gA(m) = 1000000
If m <= wCount Then ' 1000000 is at ga(m)
' check that there are no 1000s
j = 1
Do
j = j + 1
Loop Until j >= m Or gA(j) = 1000
If j < m Then
MsgBox "Cannot process thousands of millions"
Exit Sub
End If
j = 1
Do
j = j + 1
Loop Until j >= m Or gA(j) = 100
If j < m Then
gA(j) = gA(j) * gA(j - 1)
gA(j - 1) = 0
gB(j) = 1
End If
LL = 0
For j = 1 To m - 1
L = L + gA(j)
gA(j) = 0
gB(j) = 0
Next j
gA(m) = L * gA(m)
gB(m) = 1
Else
m = 0
End If ' 1000000 processed

mm = j + 1
If mm <= wCount Then
Do
mm = mm + 1
Loop Until mm > wCount Or gA(mm) = 1000
End If
If mm <= wCount Then ' 1000 is at ga(mm)
j = m + 1
Do
j = j + 1
Loop Until j >= mm Or gA(j) = 100
If j < mm Then ' have 100 preceeding 1000
gA(j) = gA(j) * gA(j - 1)
gA(j - 1) = 0
gB(j) = 1
End If
LL = 0
For j = m + 1 To mm - 1
LL = LL + gA(j)
gA(j) = 0
gB(j) = 1
Next j
gA(mm) = LL * gA(mm)
gB(mm) = 1
Else
mm = m
End If ' 1000 is at mmth entry

mmm = mm + 1
If mmm <= wCount Then
Do
mmm = mmm + 1
Loop Until mmm > wCount Or gA(mmm) = 100
End If
If mmm <= wCount Then ' 100 is at ga(mmm)
gA(mmm) = gA(mmm - 1) * gA(mmm)
gA(mmm - 1) = 0
gB(mmm) = 1
Else
mm = m
End If ' 100 is at mmmth entry

LLL = 0
For j = 1 To wCount
LLL = LLL + gA(j)
Next j

If isThousandsComma Then
s = Format(LLL, "Standard")
s = Left(s, Len(s) - 3)
Else
s = Str(LLL)
End If

R.Text = Trim(s)
R.Select
End Sub

Function removeZeros(gA() As Long, gB() As Long, ByVal wCount As Long) As Long
Dim q As Long
Dim z As Long
For q = wCount To 1 Step -1
If gA(q) = 0 Then
z = q
Do While z < wCount
gA(z) = gA(z + 1)
gB(z) = gB(z + 1)
z = z + 1
Loop
wCount = wCount - 1
End If
Next q
removeZeros = wCount
End Function


2015-01-07 23:05:06

Kevin

And for a really sophisticated approach:

http://gregmaxey.mvps.org/word_tip_pages/spell_out_currency.html


2015-01-07 11:19:49

Kevin

Here are my mods to Ken's improvements (Good job Ken!) The mods suppress the trailing word "zero" when needed and also suppresses the extra space when a "." is encountered at the end of sentence.

Sub BigCardText()
Dim sDigits As String
Dim sBigStuff As String
Dim rDollar As Range
Dim rNextChar As Range
Dim bEOS As Boolean
sBigStuff = ""
bEOS = False

' Select the full number in which the insertion point is located
Selection.MoveLeft unit:=wdWord, Count:=1, Extend:=wdMove
Set rNextChar = Selection.Range
rNextChar.End = rNextChar.Start + 1
If rNextChar.Text = "$" Then Selection.MoveRight , Count:=1, Extend:=wdMove ' covers case where number including $ is selected

Selection.MoveRight unit:=wdWord, Count:=1, Extend:=wdExtend
If Selection.Range.Text = "." Then GoTo nERR ' insertion point precedes a dot

If Not IsNumeric(Selection.Text) Then GoTo nERR

Set rDollar = Selection.Range
Set rNextChar = Selection.Range
rNextChar.Start = rNextChar.End
rNextChar.MoveEnd unit:=wdCharacter, Count:=1
If rNextChar.Text = "." Then ' there is a decimal point as next char. It may be an end of sentence
rNextChar.Start = rNextChar.End
rNextChar.MoveEnd unit:=wdCharacter, Count:=1
If rNextChar.Text <> Chr(13) And rNextChar.Text <> " " Then GoTo nERR
bEOS = True
End If
rDollar.MoveStart unit:=wdCharacter, Count:=-1
rDollar.End = rDollar.Start + 1
If rDollar.Text = "." Or rDollar = "," Then GoTo nERR ' leading decimal point

' Store the digits in a variable
sDigits = Trim(Selection.Text)

If Val(sDigits) > 999999 Then
If Val(sDigits) <= 999999999 Then
sBigStuff = Trim(Int(Str(Val(sDigits) / 1000000)))
' Create a field containing the big digits and
' the cardtext format flag
Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldEmpty, Text:="= " + sBigStuff + " * CardText", _
PreserveFormatting:=True

' Select the field and copy it
Selection.MoveLeft unit:=wdWord, Count:=1, Extend:=wdExtend
sBigStuff = Selection.Text & " million "
sDigits = Right(sDigits, 6)
End If
End If
If Val(sDigits) <= 999999 Then
' Create a field containing the digits and the cardtext format flag
Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldEmpty, Text:="= " + sDigits + " * CardText", _
PreserveFormatting:=True
' Select the field and copy it
Selection.MoveLeft unit:=wdWord, Count:=1, Extend:=wdExtend

' Checks for exactly 0, 1 million , 10 million and 100 million to supress trailing "zero"
If Val(sDigits) <> 0 Then
sDigits = sBigStuff & Selection.Text
Else
If sBigStuff <> "" Then
sDigits = Trim(sBigStuff)
Else
sDigits = Selection.Text
End If
End If

If rDollar.Text = "$" Then
sDigits = sDigits & " dollars"
rDollar.Text = ""
End If

' Now put the words in the document
Selection.TypeText Text:=sDigits
If bEOS = False Then
Selection.TypeText Text:=" "
End If
Selection.Range.Sentences(1).Select
Selection.Range.Case = wdTitleSentence
Selection.Collapse direction:=wdCollapseEnd
Else
MsgBox "Number too large", vbOKOnly
End If
Exit Sub

nERR:
MsgBox "Is not an integer"
End Sub


2014-12-31 17:03:23

Ken Endacott

The following macro will check that the selection is a valid integer and does not contain comma separators. If the number is preceded by a $ then the word dollars is added (it will give plural for $1). It also gives sentence case to the whole sentence. It does not include Kevin's mods to remove zero on large numbers.

Sub BigCardText()
Dim sDigits As String
Dim sBigStuff As String
Dim rDollar As Range
Dim rNextChar As Range
sBigStuff = ""

' Select the full number in which the insertion point is located
Selection.MoveLeft unit:=wdWord, Count:=1, Extend:=wdMove
Set rNextChar = Selection.Range
rNextChar.End = rNextChar.Start + 1
If rNextChar.Text = "$" Then Selection.MoveRight , Count:=1, Extend:=wdMove ' covers case where number including $ is selected

Selection.MoveRight unit:=wdWord, Count:=1, Extend:=wdExtend
If Selection.Range.Text = "." Then GoTo nERR ' insertion point precedes a dot

If Not IsNumeric(Selection.Text) Then GoTo nERR

Set rDollar = Selection.Range
Set rNextChar = Selection.Range
rNextChar.Start = rNextChar.End
rNextChar.MoveEnd unit:=wdCharacter, Count:=1
If rNextChar.Text = "." Then ' there is a decimal point as next char. It may be an end of sentence
rNextChar.Start = rNextChar.End
rNextChar.MoveEnd unit:=wdCharacter, Count:=1
If rNextChar.Text <> Chr(13) And rNextChar.Text <> " " Then GoTo nERR
End If
rDollar.MoveStart unit:=wdCharacter, Count:=-1
rDollar.End = rDollar.Start + 1
If rDollar.Text = "." Or rDollar = "," Then GoTo nERR ' leading decimal point

' Store the digits in a variable
sDigits = Trim(Selection.Text)

If Val(sDigits) > 999999 Then
If Val(sDigits) <= 999999999 Then
sBigStuff = Trim(Int(str(Val(sDigits) / 1000000)))
' Create a field containing the big digits and
' the cardtext format flag
Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldEmpty, Text:="= " + sBigStuff + " * CardText", _
PreserveFormatting:=True

' Select the field and copy it
Selection.MoveLeft unit:=wdWord, Count:=1, Extend:=wdExtend
sBigStuff = Selection.Text & " million "
sDigits = Right(sDigits, 6)
End If
End If
If Val(sDigits) <= 999999 Then
' Create a field containing the digits and the cardtext format flag
Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldEmpty, Text:="= " + sDigits + " * CardText", _
PreserveFormatting:=True
' Select the field and copy it
Selection.MoveLeft unit:=wdWord, Count:=1, Extend:=wdExtend
sDigits = sBigStuff & Selection.Text
If rDollar.Text = "$" Then
sDigits = sDigits & " dollars"
rDollar.Text = ""
End If
' Now put the words in the document
Selection.TypeText Text:=sDigits
Selection.TypeText Text:=" "
Selection.Range.Sentences(1).Select
Selection.Range.Case = wdTitleSentence
Selection.Collapse direction:=wdCollapseEnd
Else
MsgBox "Number too large", vbOKOnly
End If
Exit Sub

nERR:
MsgBox "Is not an integer"
End Sub


2014-12-10 10:39:39

Kevin

Sam,

You need to cut 'n paste the code into the VBA editor within Word. See the following article to get you started.

http://visualbasic.about.com/od/learnofficevbnet/a/office2007vba.htm


2014-12-10 02:16:39

sam

i am not able to convert numbers into text, please mail me in detail how to create macro and how to run it in MS word 2007


2013-05-21 08:14:47

Kevin

Forgot to include above that what is added is the check to supress the extra text, "zero", printed when the value being converted over 1 million has all zeroes. For example 10,000,000 was being converted to "ten million zero".


2013-05-20 16:40:58

Kevin

Sub BigCardText()
Dim sDigits As String
Dim sBigStuff As String

sBigStuff = ""

' Select the full number in which the insertion point is located
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdMove
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend

' Store the digits in a variable
sDigits = Trim(Selection.Text)

If Val(sDigits) > 999999 Then
If Val(sDigits) <= 999999999 Then
sBigStuff = Trim(Int(Str(Val(sDigits) / 1000000)))
' Create a field containing the big digits and
' the cardtext format flag
Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldEmpty, Text:="= " + sBigStuff + " * CardText", _
PreserveFormatting:=True

' Select the field and copy it
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend
sBigStuff = Selection.Text & " million "
sDigits = Right(sDigits, 6)
End If
End If
If Val(sDigits) <= 999999 Then
' Create a field containing the digits and the cardtext format flag
Selection.Fields.Add Range:=Selection.Range, _
Type:=wdFieldEmpty, Text:="= " + sDigits + " * CardText", _
PreserveFormatting:=True

' Select the field and copy it
Selection.MoveLeft Unit:=wdWord, Count:=1, Extend:=wdExtend

' Checks for exactly 0, 1 million , 10 million and 100 million
If Val(sDigits) <> 0 Then
sDigits = sBigStuff & Selection.Text
Else
If sBigStuff <> "" Then
sDigits = Trim(sBigStuff)
Else
sDigits = Selection.Text
End If
End If

' Now put the words in the document
Selection.TypeText Text:=sDigits
Selection.TypeText Text:=" "
Else
MsgBox "Number too large", vbOKOnly
End If
End Sub


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.