Can I convert a number to words in VBA?

J

Jules

I have a macro which contains a text box asking users to insert a number

Once they have entered their number I convert it to a value (Val) but then
want to convert the value to words so that I get, for example, the following:

"five (5)"

Can the number be converted to words?
 
J

Jezebel

Google brings up several macros for the purpose, eg
http://www.meadinkent.co.uk/xlnumberstext.htm

Outputting numbers both words and digits (as in your example) is a "layman's
pretension to legalese". The technique was introduced in the 19th century to
deal with the strange hand-written script used by legal clerks of the day.
It became irrelevant when typewriters were introduced, and has been an
absurdity ever since. It has NO legal significance. It introduces an
ambiguity (ie the possibility of the two representations being different)
where previously there was none.
 
M

macropod

Hi Jules,

If you're wanting to output the value as text in the document, it would
probably be easiest to add a field at the required position with a '\*
Cardtext' switch, then unlink it. For example:

Sub NumTextCombo()
Dim Val As Double
Val = InputBox("Value")
With Selection
ActiveDocument.Fields.Add(.Range, , Text:="=" & Val & _
" \* Cardtext", Preserveformatting:=False).Unlink
.Collapse Direction:=wdCollapseEnd
.InsertAfter " (" & Val & ")"
End With
End Sub

Cheers
 
J

Jules

thanks, works great

macropod said:
Hi Jules,

If you're wanting to output the value as text in the document, it would
probably be easiest to add a field at the required position with a '\*
Cardtext' switch, then unlink it. For example:

Sub NumTextCombo()
Dim Val As Double
Val = InputBox("Value")
With Selection
ActiveDocument.Fields.Add(.Range, , Text:="=" & Val & _
" \* Cardtext", Preserveformatting:=False).Unlink
.Collapse Direction:=wdCollapseEnd
.InsertAfter " (" & Val & ")"
End With
End Sub

Cheers

--
macropod
[MVP - Microsoft Word]


Jules said:
I have a macro which contains a text box asking users to insert a number

Once they have entered their number I convert it to a value (Val) but then
want to convert the value to words so that I get, for example, the following:

"five (5)"

Can the number be converted to words?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top