Solved

run code on all of the tables omitting some of them

Posted on 2014-02-11
2
263 Views
Last Modified: 2014-02-11
Dear Experts:

I would like to run below code (courtesy by Rgonzo1971, EE) not only on the selected table but on all of the tables in the active document with the exception of table 3, 5, 7 and 10.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub Format_Columns_Add_Decimal_tabs_selected_table()

Dim mytable As Table
Set d = ActiveDocument
Set mytable = Selection.Tables(1)
    With mytable
        For IdxRow = 2 To mytable.Rows.Count
            For IdxCol = 2 To 3
                Set c = mytable.Cell(IdxRow, IdxCol)
                c.Range.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(1.7) _
                    , Alignment:=wdAlignTabDecimal, Leader:=wdTabLeaderSpaces
                 Next
        Next
       .PreferredWidth = 97.5
       .PreferredWidthType = wdPreferredWidthPercent
       .Columns(2).Width = CentimetersToPoints(3.1)
       .Columns(3).Width = CentimetersToPoints(3.1)
       .PreferredWidth = 97.5
       .PreferredWidthType = wdPreferredWidthPercent
    End With
End Sub

Open in new window

0
Comment
Question by:AndreasHermle
2 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39849584
Hi,

pls try

Sub Format_Columns_Add_Decimal_tabs_selected_table()

'to be expanded by inserting a decimal tab at 1.7 cm in all cells starting from row 2 of Column 2 and 3


Dim mytable As Table
For IdxTable = 1 To ActiveDocument.Tables.Count
    Select Case IdxTable
        Case 3, 5, 7, 10
        ' do nothing
        Case Else
            Set mytable = ActiveDocument.Tables(IdxTable)
            With mytable
               .PreferredWidth = 97.5
               .PreferredWidthType = wdPreferredWidthPercent
               .Columns(2).Width = CentimetersToPoints(3.1)
               .Columns(3).Width = CentimetersToPoints(3.1)
               .PreferredWidth = 97.5
               .PreferredWidthType = wdPreferredWidthPercent
                For IdxRow = 2 To .Rows.Count
                    For IdxCol = 2 To 3
                        Set c = .Cell(IdxRow, IdxCol)
                        c.Range.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(1.7) _
                            , Alignment:=wdAlignTabDecimal, Leader:=wdTabLeaderSpaces
                    Next
                Next
            End With
    End Select
Next
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:AndreasHermle
ID: 39850055
Great job, as always, thank you very much for your great and professional support.

Regards, Andreas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now