Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"spell dollars" function for WORD

Status
Not open for further replies.

merlizbet

Technical User
Oct 4, 2012
36
US
Hey folks,

I'm creating a simple WORD fill-in form for a co-worker to print checks. To help avoid errors, I was going to attempt to add a custom WORD function that would translate the number-formatted dollar amount into the long-hand dollar amount. I've found and am using a function written by someone else to do this trick in Access. I'd call myself a "Big F/little t", Functional/technical person and I'm generally relatively successful doing stuff with VBA in Access; but I really have no idea how to (or if I can) use this same (or modified) function in WORD. I copy/pasted the Access VBA into a WORD VBA module, but a very quick Google search hasn't even told me how I could call it. Can anyone give me pointers on how to go about translating Access VBA into WORD VBA (if that's possible) and then calling it. That's probably too broad of a question, but I needed to start somewhere. :)

Thanks for you input!
 
A Pole, a Slovak and a Russian are hunting for bear. They meet a bear couple with a cub. One of the bears consumed one of the hunters. Who ate who?
The Czech's in the male!
🤑

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
You do realise this can all be done without VBA of any kind???

For whole dollars, you could simply set the formfield's 'calculate on exit' property and use a formula field to reference formfield's bookmark combined with the \* CardText switch. Word also has a \* DlooarText switch for dollars & cents, but the cents are displayed in the 00/100 format, which I don't care for. A bit more field coding, though, can display both the dollars and cents as text. For example, such a field might be code as:
{QUOTE "{=INT(Val) \* CardText} dollar{=INT(Val)-1 \# "s;s;"}{IF{=MOD(Val,1) \# 0.00}> 0 " and {={=MOD(Val,1)*100 \# 0} \* CardText } cent{=INT(MOD(Val,1)*100-1) \# "s;s;"}"}"}
or, if you want to include the 'and' text that UK English includes in such text, the field might be coded as:
{QUOTE {SET AbsVal {=ABS(Val)}} {IF{=Val}< 0 "Minus "} {IF{=INT(AbsVal/100000000)}<> 0 "{=INT(AbsVal/100000000) \*Cardtext} hundred "} {IF{=MOD(INT(AbsVal/1000000),100)} <> 0 "{IF{=INT(AbsVal/100000000)}<> 0 "and "}"} {IF{=INT(AbsVal/1000000)}<> 0 "{=MOD(INT(AbsVal/1000000),100) \*Cardtext} million, "} {IF{=INT(AbsVal/100000)}<> 0 "{=MOD(INT(AbsVal/100000),10) \*Cardtext} hundred "} {IF{=MOD(INT(AbsVal1000),100)} <> 0 "{IF{=INT(AbsVal/100000)}<> 0 "and "}"} {IF{=INT(AbsVal/1000)}<> 0 "{=MOD(INT(AbsVal/1000),100) \*Cardtext} thousand, "} {IF{=MOD(INT(AbsVal/100),10)}<> 0 "{=MOD(INT(AbsVal/100),10) \*Cardtext} hundred "} {IF{=MOD(INT(AbsVal),100)}<> 0 "{IF{=INT(AbsVal/100)}<> 0 "and "}{=MOD(INT(AbsVal),100) \*Cardtext} "} {=INT(AbsVal) \# \dollar;;}{IF{=INT(AbsVal)}> 1 "s"} {IF{=MOD(AbsVal,1)}<> 0 "{IF{=INT(AbsVal)}<> 0 " and "}{=MOD(AbsVal,1)*100 \*Cardtext} cent{IF{=MOD(AbsVal,1)}> 0.01 s}"} \* FirstCap}
Obviously, the second one is rather more complex...

In both cases, a formfield with the intewrnal bookmark name 'Val' is assumed.

Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. The spaces represented in the field construction are all required.

For a macro to convert the above into working field codes, see Convert Text Representations of Fields to Working Fields in the Mailmerge Tips and Tricks threads at:
or:

Cheers
Paul Edstein
[MS MVP - Word]
 
Skip,
If "A Pole, a Slovak and a Russian are hunting for bear.", then where did the Czech come from? [ponder]

I guess this is a very old joke, back when there was a Czechoslovakia... :)

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Yea, I failed to state that they arrived in a Yugo.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
So now we have a time reference (for the existence of Czechoslovakia), but Yugo was made in Yugoslavia (also not there any more). Skoda would be a better choice of a car.

Nice try to save yourself, tho... :)

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Oh well, Czech that one off the list!👎

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top