Solved

run code on all of the tables omitting some of them

Posted on 2014-02-11
2
262 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
Great job, as always, thank you very much for your great and professional support.

Regards, Andreas
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
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…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.

763 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

10 Experts available now in Live!

Get 1:1 Help Now