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 2004

Tip: Looking for answers? Try searching our database.

Aligning Decimals in Table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James Pannozzi - 30 Jul 2004 19:37 GMT
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
Takuon Soho - 31 Jul 2004 21:09 GMT
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

> I have numbers such as the following
> in some cells in a Word 2000 table
[quoted text clipped - 36 lines]
>     Next
> End Sub
 
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.