PDA

View Full Version : Format Currency



Rottimom
09-18-2013, 09:55 AM
I have the following code that is totaling a cell in a word table for me. This cell is currency so I need the results to include two spaces after the decimal point. Right now if it sums 10.00 and 20.00 the output is just 30 I need it to be 30.00.

Set oRng = .Cell(oTbl.Rows.Count, 8).Range
oRng.Collapse wdCollapseStart
ActiveDocument.Fields.Add oRng, wdFieldEmpty, "= Sum(Above)"
Set oTotal = .Cell(oTbl.Rows.Count, 8).Range
ActiveDocument.Bookmarks("bmTotal").Select
Selection.TypeText oTotal

gmaxey
09-18-2013, 11:10 AM
Sub ScratchMacror()
Dim lngTotal As Long
lngTotal = 11
MsgBox FormatCurrency(lngTotal, 2)
'
MsgBox Format(lngTotal, "#.00")
End Sub

Rottimom
09-18-2013, 01:23 PM
Thank you for the quick reply. I have tried modifying my code adding both FormatCurrency(expression, 2) and Format(expression, "#.00") with no luck.

When I use:

Selection.TypeText FormatCurrency(oTotal, 2) I get an Run-time error '13' Type mismatch

If I use:
Selection.TypeText Format(oTotal, "#.00) it returns the same value 30 instead of 30.00.

gmaxey
09-18-2013, 05:15 PM
What is oTotal?

Rottimom
09-19-2013, 01:30 PM
It is just the expression I am using to read the last row, column 8 that has the total. I actually need both the expression oTotal and the ActiveDocument.Fields.Add oRng, wdFieldEmpty, "= Sum(Above)" to be in currency format.

gmaxey
09-19-2013, 02:25 PM
The field code need to be: = Sum(Above) \# “$,#.00”

As long as oTotal is in fact a long variable then it should not be causing and error.