Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / July 2008

Tip: Looking for answers? Try searching our database.

How to format values in a table ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob - 23 Jul 2008 21:44 GMT
I have a word table that has a cell containing a numerical value... I want
to add leading zeros to this value via a formula...

I am new to Word VBA, but I know that this can be done using Access VBA.
Apparently Word VBA <> Access VBA correct ?

Otherwise this should work....

Format$(Fieldname, "000000")

or

Right$("000000" & Trim$(Fieldname), 6)

Any Word Equivalents for these ?
macropod - 23 Jul 2008 22:24 GMT
Hi Rob,

How is the value getting into the cell (eg formfield, formula field, vba, typing)?

Signature

Cheers
macropod
[MVP - Microsoft Word]

>I have a word table that has a cell containing a numerical value... I want
> to add leading zeros to this value via a formula...
[quoted text clipped - 11 lines]
>
> Any Word Equivalents for these ?
Rob - 23 Jul 2008 23:21 GMT
Thanks for responding...

It is actually coming from a 3rd party erp system... but my guess would be
"formfield" as you map them from the erp system into a table in the word doc
template.

> Hi Rob,
>
[quoted text clipped - 16 lines]
>>
>> Any Word Equivalents for these ?
macropod - 24 Jul 2008 01:01 GMT
Hi Rob,

OK, to test whether the value is in a formfield, press Alt-F9. If the value is in any sort of field, the cell's contents will change
to something bound by a pair of field braces (ie '{}'). If it's a formfield you should see something like '{ FORMTEXT }' or '{
FORMTEXT { =12345 }}'. If that's what you see, right-click on the field and choose 'properties', then make sure the 'type' is set to
'number' and insert as many 0s as you need in the 'number format' box. If you make these changes to the template the document is
based on, any new documents will automatically get the required number of leading 0s.

No vba required.

Press Alt-F9 again to toggle the field code display off.

Signature

Cheers
macropod
[MVP - Microsoft Word]

> Thanks for responding...
>
[quoted text clipped - 18 lines]
>>>
>>> Any Word Equivalents for these ?
Rob - 24 Jul 2008 11:01 GMT
Thanks again for your time...

But I guess it is not a formfield after all... I pressed Alt-F9 and all that
was present was an empty table.   I assume the erp is populating it
dynamically and thus there is no way to intervene with a formatting
override.

rob

> Hi Rob,
>
[quoted text clipped - 38 lines]
>>>>
>>>> Any Word Equivalents for these ?
Graham Mayor - 24 Jul 2008 12:56 GMT
Given that the content appears to be text, the following macro will format a
chosen column in the format "00000"

Sub FormatColumn()
Dim cTable As Table
Dim rName As Range
Dim sCell As String
Dim rText As Range
Dim i As Long
Dim v As Long

v = InputBox("Format which column", , 3)
'v = 3
Set cTable = ActiveDocument.Tables(1)

On Error Resume Next
For i = 1 To cTable.Rows.Count
   Set rName = cTable.Cell(i, v).Range
   sCell = Left(rName, Len(rName) - 1)
   rName = Replace(rName, sCell, Format(sCell, "00000"))
Next i
End Sub

http://www.gmayor.com/installing_macro.htm

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thanks again for your time...
>
[quoted text clipped - 56 lines]
>>>>>
>>>>> Any Word Equivalents for these ?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.