Microsoft Office Tutorials and References
In Depth Information
Displaying a Number in Millions as Text
View the Appendix to learn how to store this procedure
in a Standard module.
Option explicit¶
' * * * * *¶
Sub CreateCardTextFieldMillions()¶
'Variable declaration¶
Dim fld As Word.Field, rng As Word.Range¶
Dim szSepChar As String, szBkm As String¶
Dim szQuotes As String¶
szQuotes = Chr(34)¶
szBkm = "bkm"¶
szSepChar = System.PrivateProfileString( _¶
"", "HKEY_CURRENT_USER\Control Panel\International", _¶
"sList")¶
'Insert the outermost level; QUOTE field¶
Set fld = ActiveDocument.Fields.Add( _¶
Range:=Selection.Range, Type:=wdFieldQuote, _¶
Text:="bkm bkm bkm bkm", PreserveFormatting:=False)¶
Set rng = fld.Code¶
'Insert the second level, first SET field¶
InsertFieldInFieldCode rng, szBkm, "Set n bkm"¶
InsertFieldInFieldCode rng, szBkm, "NrToText"¶
'Determine the millions part of the number¶
InsertFieldInFieldCode rng, szBkm, "Set m bkm"¶
InsertFieldInFieldCode rng, szBkm, "= int(bkm/1000000)"¶
InsertFieldInFieldCode rng, szBkm, "n"¶
'Determine the remainder¶
InsertFieldInFieldCode rng, szBkm, "Set r bkm"¶
InsertFieldInFieldCode rng, szBkm, "= MOD(bkm" & szSepChar _¶
& "1000000)"¶
InsertFieldInFieldCode rng, szBkm, "n"¶
'Determine if NrToText number < or >= 1 million¶
InsertFieldInFieldCode rng, szBkm, "If bkm < 1000000 " & _¶
szQuotes & "bkm" & szQuotes & " " & szQuotes & "bkm" _¶
& szQuotes & " \* lower \* CharFormat"¶
InsertFieldInFieldCode rng, szBkm, "n"¶
'If less, simply transform into dollartext¶
InsertFieldInFieldCode rng, szBkm, "n \* dollartext"¶
'Insert a container for concatenated result¶
'if greater than or equal to¶
InsertFieldInFieldCode rng, szBkm, _¶
"Quote " & szQuotes & "bkm millionbkm" & szQuotes¶
'If more than a million, insert the millions number as CardText¶
InsertFieldInFieldCode rng, szBkm, "m \* cardtext"¶
'If the remainder = 0...¶
InsertFieldInFieldCode rng, szBkm, "If bkm < 1 " & szQuotes & _¶
" and bkm/100" & szQuotes & " " & szQuotes & " bkm" & szQuotes¶
InsertFieldInFieldCode rng, szBkm, "r"¶
Wrd
Search JabSto ::




Custom Search