Macro for Table Headers

J

Jen

I am currently using the following macro to set all tables with
heading rows repeat, and it works great:

Sub TablesAllHeaderRepeat()

Dim i As Long
With ActiveDocument
For i = 1 To .Tables.Count
.Tables(i).Rows(1).HeadingFormat = True
Next i
End With
Selection.HomeKey Unit:=wdStory

End Sub

However, now I want to modify that macro so that it only adjusts the
heading row IF that row is a certain style. So...

for each table
If the style applied to the row is "TableHeading", then set the
heading row to repeat
Otherwise, do nothing.

Thoughts?
 
P

Pesach Shelnitz

Hi Jen,

You macro only needs a small change to make it do what you want. It just
needs to check the Style property of the Range object for the row, as follows:

Sub TablesAllHeaderRepeat()

Dim i As Long
With ActiveDocument
For i = 1 To .Tables.Count
If .Tables(i).Rows(1).Range.Style = "TableHeading" Then
.Tables(i).Rows(1).HeadingFormat = True
End If
Next i
End With
Selection.HomeKey Unit:=wdStory

End Sub

Bear in mind that the condition will be true only if the TableHeading style
is applied to all the cells in the first row.
 
J

Jen

Hi Jen,

You macro only needs a small change to make it do what you want. It just
needs to check the Style property of the Range object for the row, as follows:

Sub TablesAllHeaderRepeat()

Dim i As Long
With ActiveDocument
    For i = 1 To .Tables.Count
        If .Tables(i).Rows(1).Range.Style = "TableHeading" Then
            .Tables(i).Rows(1).HeadingFormat = True
        End If
    Next i
End With
Selection.HomeKey Unit:=wdStory

End Sub

Bear in mind that the condition will be true only if the TableHeading style
is applied to all the cells in the first row.

Thank you very much, that worked perfectly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top