Avatar of mvp1985
mvp1985
 asked on

How to tell word to spell out a number in digits

I have a very large amount of numbers in word that needs to be presented in both ways, numbers and spelled out. All the numbers are present in digits, but so far I need to type them manually to have them spelled out. Is there a way to automatically do this?
Microsoft Word

Avatar of undefined
Last Comment
mvp1985

8/22/2022 - Mon
Eirman

There is no way to do it natively in word. You will have to use this macro.
http://word.tips.net/T000203_Converting_Numbers_to_Text.html
Frank Helk

Open the VBA editor and put this into your document's or normal.dot macro code:

Sub Digits2Numbers()

    Dim digits As String
    Dim spelled As String
    
    digits = Selection.Text
    spelled = "#"
    
    For i = 1 To Len(digits)
        If i > 1 And Len(digits) > 1 Then spelled = spelled + "-"
        Select Case Mid(digits, i, 1)
        Case "0"
            spelled = spelled + "Zero"
        Case "1"
            spelled = spelled + "One"
        Case "2"
            spelled = spelled + "Two"
        Case "3"
            spelled = spelled + "Three"
        Case "4"
            spelled = spelled + "Four"
        Case "5"
            spelled = spelled + "Five"
        Case "6"
            spelled = spelled + "Six"
        Case "7"
            spelled = spelled + "Seven"
        Case "8"
            spelled = spelled + "Eight"
        Case "9"
            spelled = spelled + "Nine"
        Case "."
            spelled = spelled + "Dot"
        Case ","
            spelled = spelled + "Comma"
        Case "$"
            spelled = spelled + "Dollar"
        Case " "
            spelled = spelled + "Space"
        Case "-"
            spelled = spelled + "Minus"
        Case "+"
            spelled = spelled + "Plus"
        Case Else
            spelled = spelled + "???"
        End Select
    Next i
    spelled = spelled + "#"

    Dim objClipboard As Object
    Set objClipboard = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
    objClipboard.SetText spelled
    objClipboard.PutInClipboard
    Set objClipboard = Nothing
End Sub

Open in new window


Add the macro to your menu strip and/or assign a shortkey combination to it.

Usage:

Type the number you want to convert, and select it. Run the macro. The converted number will be in the clipboart afterwards. To replace the number just type CRTL-V afterwards, since the number string is already selected. To use it elsewhere, just navigate to theright spot and press CTRL-V there.

Example:

     123456 78,90.5x+-

would return in the clipboard

     #One-Two-Three-Four-Five-Six-Space-Seven-Eight-Comma-Nine-Zero-Dot-Five-???-Plus-Minus#

For different start/end coding and separator just adjust the strings in the code ...

By the way that macro is independent to the number's length ... and with some more things in the select statement it could even be used tor translating text into a phonetic alphabet (Alpha, Bravo, Charlie, Delta, Echo, ... see here for more info).
Eirman

Experiment with this ....

Select a number in word (e.g. 2750)
Press Ctrl+F9 to embed it in a field.
Use Alt+F9 to show/hide the field as necessary.

Edit the field to match the following format:
{=VALUE \* CardText}      that is .... {=2750 \* CardText}

Press F9 to update the field.    Result = two thousand seven hundred fifty
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
GrahamSkan

Eirman,
Missed your welcome later contribution.
Eirman

Point noted and taken on board GrahamSkan
ASKER CERTIFIED SOLUTION
Eric Fletcher

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Eric Fletcher

An addendum to my comment above: If you want to have the field code results converted to text instead of existing as calculated field codes, select the results and press Ctrl-Shift-F9. For the mail merge field codes, just run the "Finish & Merge" to produce a new document with the values.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
mvp1985

ASKER
The {MERGEFIELD "Amount" \*CardText } works perfect and is exactly what I need. But how can I assign the previous form field instead of "Amount"? This is important, since I run a macro on exiting the form field that has the number in digits, that unprotected the document, pastes a new page with the same form fields and text, and then re-protects the document.

Since the price is always different on each document page, but the formfield that contains the correct digits is always the one before the spelled out number, I know bookmarks would not work, unless there is a way to create a bookmark every time the makro runs upon exiting the price form field.
Any suggestions on this?
Eric Fletcher

I'm not sure I follow what you need to do here. Can you post an example?

The format switches will work with any field code that can return a numeric value, but you'd need to find away to refer to the value in some way with a field code. Perhaps the STYLEREF could be used if you can have the value from the formfield result tagged with a style as shown below.
Using STYLEREF to report a value as cardinal textFor clarity, I captured the 1st screen shot in the Draft mode so the paragraph style names would be shown in the style area pane on the left (File Options > Advanced > Display, Style area pane width in Draft and Outline views). The style pane will only show the style name associated with paragraphs, so I set the character style colour to brown to make it more visible. This can be handy for testing, and you can change the style's colour back to Auto once you know it works okay.
mvp1985

ASKER
Basically I am developing a word document that is used for evaluations of art and jewelery for which i use form fields and text describing what goes into the form field. I do this so I can quickly enter the text and then just advance with the tab key. Since every customer is different, I don't know ho many items I need to evaluate, so I use a macro, which runs at the exit of the last form field on the page, that enters a page break, and the same form fields and descriptions (in order for this to work, the macro unprotects the document, and later protects it again, so I can use tab again).  The last item I enter is the estimated price of the piece, but for legal purposes I also need to enter it in non-numerical form right beneath the numerical form. (so for example:

 Estimated price: $40.00
                                 Forty US Dollar

The mergefield you mentioned earlier works perfectly when I enter the number into the "amount" when I establish the meregield. But, since I have often hundreds over hundreds of these prices, I would love for a way that it is automated completley, and all I need to do is put the numerical price in, and the non-numerical amount is automatically entered below. So yes, I need to find a way to refer to the numeric value somehow. Any suggestions on how to refer automatically?
Your help has saved me hundreds of hours of internet surfing.
fblack61