Solved

run code on all of the tables omitting some of them

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

776 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