Set Decimal Tabstops (1.7 cm) in Column 2 and Column 3 for tables 2 to penultimate one (Using VBA)

Andreas Hermle
Andreas Hermle used Ask the Experts™
Dear experts:

I would like to set decimal tabstops (position 1.7 cm) in Column 2 and Column 3 for tables 2 to the penultimate one of the currently active document (running a macro). The header rows should be left alone, i.e. no decimal tab stops for the header rows.

I have attached a sample for your convenience. In Germany we use a comma as a decimal point. Word for Windows might convert that to a 'dot / point' if you open it on your PC in an angloamerican country or India.

Help is much appreciated. Thank you very much in advance

Regards, Andreas
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Hi Andreas
The carers have just put my partner to bed, so I can relax with this.
Sub SetDecimalTabStops()
    Dim tbl As Table
    Dim r As Integer
    Dim c As Integer
    Dim para As Paragraph
    Dim t As Integer
    For t = 2 To ActiveDocument.Tables.Count - 1
        Set tbl = ActiveDocument.Tables(t)
        For c = 2 To 3
            For r = 2 To tbl.Rows.Count
                Set para = tbl.Cell(r, c).Range.Paragraphs.First
                para.TabStops.Add CentimetersToPoints(1.7), wdAlignTabDecimal
             Next r
        Next c
    Next t
End Su

Open in new window

Andreas HermleTeam leader


Great Graham, works like a charm. Thank you very much, I really appreciate it.

And all the best

Kind regards, Andreas

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial