Aligning Decimals in Table

J

James Pannozzi

I have numbers such as the following
in some cells in a Word 2000 table
which are pt\ut there by VBA.
The numbers are in cells in column 1, in rows 5, 6 and 7

$40,000.00 for the first period
$75,000.12 for the next period
$100,000.19 at age 89

I would like to execute some VBA which would align
the numbers by the decimal point so that the above
would appear as

$40,000.00 for the first period
$75,000.12 for the next period
$100,000.19 at age 89

I tried the following VBScript (see below) (which applies to the entire
column)
and all it does is move numbers such as 3. in other cells of column 1
off to the right but has no effect on the dollar amounts mentioned.

How does one do it??

Thanks Jim

Sub DecimalTabStopInTableColumn()
Dim tbl 'As Word.Table
Dim col 'As Word.Column
Dim cel 'As Word.Cell

Set tbl = objWord.ActiveDocument.Tables(1)
Set col = tbl.Columns(1)
For Each cel In col.Cells
cel.Range.ParagraphFormat.TabStops.Add
40,wdAlignTabDecimal,wdTabLeaderSpaces
'Alternative:
' cel.Range.Paragraphs.Style = "TableColumnDecimalAlign"
Next
End Sub
 
T

Takuon Soho

OK, I see how to do it
i.e.

cel.Range.ParagraphFormat.TabStops.Add
40,wdAlignTabDecimal,wdTabLeaderSpaces

but what's making it difficult
is trying to find the start and end points of the cells to which apply
the decimal tab.

The cells are alway delimited by cells above and below
with the same text and always occur only in column 1.

Start Text
$40,000.00
$50,000.00
$100,000.00
End Text

So now my problem is to search for "Start Text",
save the row number
then search for "End Text"
and then apply decimal tab to the intervening numeric fields.in column 1.

And of course, I have to do it for all the tables in the document.

Now let's see... what might be faster, range or selection??
(I'll bet range messes up in tables because of that clever
design strategy microsoft did that internally represents the table
as a linear vector).

Hmmmm.

Thanks
Jim
 

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