How to format values in a table ?

R

Rob

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 ?
 
M

macropod

Hi Rob,

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

Rob

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.


macropod said:
Hi Rob,

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

--
Cheers
macropod
[MVP - Microsoft Word]


Rob said:
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 ?
 
M

macropod

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.


--
Cheers
macropod
[MVP - Microsoft Word]


Rob said:
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.


macropod said:
Hi Rob,

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

--
Cheers
macropod
[MVP - Microsoft Word]


Rob said:
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 ?
 
R

Rob

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


macropod said:
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.


--
Cheers
macropod
[MVP - Microsoft Word]


Rob said:
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.


macropod said:
Hi Rob,

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

--
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...

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 ?
 
G

Graham Mayor

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

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

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


macropod said:
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.


--
Cheers
macropod
[MVP - Microsoft Word]


Rob said:
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,

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

--
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... 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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top