Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. 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.
Written by Allen Wyatt (last updated May 29, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365
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.
Note:
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, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Converting Numbers to Text.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
Got a macro that processes or uses styles? You definitely need to know how many styles Word has available in the ...
Discover MoreNeed a list of all the macros you've created? Word doesn't provide a way to create such a list, but you can use the ...
Discover MoreWhen text is added to your document by a macro, and that text includes quotes or apostrophes, Word won't change the ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-10-14 01:37:29
Rose
Is there any macro that would convert in the other direction? E.g., to convert "one thousand two hundred thirty-four" to "1234"?
2019-09-04 02:14:58
Arshad
Hi פ. רוטנברג
You can use this code to replace all numbers with words.
Sub TestFunction()
Dim iCount As Integer
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = "^#"
.Forward = True
End With
Do While Selection.Find.Found = True And iCount < 1000
iCount = iCount + 1
Selection.HomeKey Unit:=wdStory
Selection.Find.Execute
If Selection.Find.Found Then
Call BigCardText
End If
Loop
End Sub
iCount is restricted to 1000 you may adjust according to your requirement.
2019-08-28 04:13:49
Arshad
is there any code to convert numbers after decimals. if possible kindly guide me
2019-07-28 03:58:44
Ch. F.
This macro is very important to me if I can use it in another language like Hebrew. Is there such a macro feasibility?
2019-07-28 03:50:51
פ. רוטנברג
How can I change some settings in this macro that will apply to all numbers in the document at one time?
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments