How to have numbers display as currency values in Word table?

Gentlefolk;

I have a Word table which is in a document that is driven by a series of macros, given to me by macropod.

This works wonderfully for what I need, but I would like to have the numbers entered into a Word table cell to be displayed as dollar values.

For example, "125" would be displayed as "$125". In this case there is no benefit to having trailing decimal and zeros ($125.00). The numbers I am dealing with are large enough that the cents would just get in the way.

Word tables don't have this format built in, so I need a simple VBA script, or an equivalent solution.

So far, my Googling has not helped at the level I need assistance.

Thx!!

Don

Answer
Answer

Actually, you may need to ensure the on-exit event fires too, so as to ensure any consequential calculations are done:

Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
  For i = 1 To .SelectContentControlsByTag("dollar").Count
    Call Document_ContentControlOnExit(.SelectContentControlsByTag("dollar")(i), False)
  Next
End With
Application.ScreenUpdating = True
End Sub

or, somewhat more refined, so as only the 'active' content control is updated:

Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
  For i = 1 To .SelectContentControlsByTag("dollar").Count
    If .SelectContentControlsByTag("dollar")(i).Range.Start <= Selection.Start Then
      If .SelectContentControlsByTag("dollar")(i).Range.End >= Selection.End Then
        Call Document_ContentControlOnExit(.SelectContentControlsByTag("dollar")(i), False)
        Exit For
      End If
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub

Cheers
Paul Edstein
(Fmr MS MVP - Word)

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 31, 2024 Views 9,719 Applies to: