View Single Post
 
Old 05-01-2016, 02:28 PM
jeffreybrown jeffreybrown is offline Windows Vista Office 2007
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Formatting all tables in doc with specific word in title

I've been able to cobble this macro together to format all tables in the doc which the first row of the table begins with either "Table" of "Figure".

Two questions:

1) How can I modify a style so it will produce TNR and 10 along with the alignment. I've tried to modify "Table Grid", but everything I read shows says this can't be modified as it is based on "Table Normal" and that you can't modify? The doc is all TNR 12 except for the body of a Table which is 10. Table header also remains 12 which I set to "Strong" in the macro below.

2) Also, are there any areas in this macro that could be modified to further use any built in styles within Word?

Code:
Sub FormatFirstTableRow()
    Dim Tbl As Table
    Dim i As Long
    Dim iRow As Row
    Application.ScreenUpdating = False
    For Each Tbl In ActiveDocument.Tables
        With Tbl
            .Range.Font.Name = "Times New Roman"
            .Range.Font.Size = 10
            .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
            .Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
            .Rows(1).Select
            If InStr(1, Selection.text, "Table") = 1 Or InStr(1, Selection.text, "Figure") = 1 Then
                With .Rows(1)
                    .Range.Style = "Strong"
                    .Borders.Enable = False
                    .Borders(wdBorderBottom).LineStyle = Options.DefaultBorderLineStyle
                    .Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
                    .Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
                End With
                .AutoFitBehavior (wdAutoFitContent)
                .Rows.HeightRule = wdRowHeightExactly
                .Rows.Height = InchesToPoints(0.2)
            End If
        End With
    Next
    ActiveDocument.Fields.Update
    Application.ScreenUpdating = True
End Sub
Reply With Quote