macro that repeats header rows of all tables?

T

Tom

Does anyone know how to make a macro that repeats the header row of
tables that span multiple pages? This is done by selecting the table
and going to Table > Heading Rows repeat. If I have a document with 20
tables, I would like to automate this via a macro, but I'm not sure how.
 
D

Doug Robbins - Word MVP

The following macro will do it:

Sub MakeHeadingRows()
Dim i As Long
With ActiveDocument
For i = 1 To .Tables.Count
.Tables(i).Rows(1).HeadingFormat = True
Next i
End With
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Stefan Blom

Use the HeadingFormat property (defined for Row objects). For example,
to set the first row of all tables in the active document to be
heading rows, use a macro such as the following:

Sub test()
Dim t As Table
For Each t In ActiveDocument.Tables
t.Rows(1).HeadingFormat = True
Next t
End Sub

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 
T

Tom

Thanks! The macro worked perfectly. I also wanted to indent the tables,
so I added another parameter in there from a different macro.

Sub Fixmytables()
Dim t As Table
For Each t In ActiveDocument.Tables
t.Rows(1).HeadingFormat = True
t.Rows.LeftIndent = CentimetersToPoints(2.9)
Next t
End Sub

Can you tell me where I would find all the parameters that I can apply
for tables? Thanks for your help.
 
T

Tom

Thanks! The macro worked perfectly. I also wanted to indent the tables,
so I added another parameter in there from a different macro.

Sub Fixmytables()
Dim t As Table
For Each t In ActiveDocument.Tables
t.Rows(1).HeadingFormat = True
t.Rows.LeftIndent = CentimetersToPoints(2.9)
Next t
End Sub

Can you tell me where I would find all the parameters that I can apply
for tables? Thanks for your help.
 
T

Tom

Thanks! The macro worked perfectly. I also wanted to indent the tables,
so I added another parameter in there from a different macro.

Sub Fixmytables()
Dim t As Table
For Each t In ActiveDocument.Tables
t.Rows(1).HeadingFormat = True
t.Rows.LeftIndent = CentimetersToPoints(2.9)
Next t
End Sub

Can you tell me where I would find all the parameters that I can apply
for tables? Thanks for your help.
 
T

Tom

Thanks! The macro worked perfectly. I also wanted to indent the tables,
so I added another parameter in there from a different macro.

Sub Fixmytables()
Dim t As Table
For Each t In ActiveDocument.Tables
t.Rows(1).HeadingFormat = True
t.Rows.LeftIndent = CentimetersToPoints(2.9)
Next t
End Sub

Can you tell me where I would find all the parameters that I can apply
for tables? Thanks for your help
 
S

Stefan Blom

Read about the Table object in Word VBA Help. Or use the Object
Browser (press F2 with the Visual Basic Editor displayed). There you
can view objects, their properties and methods, and use F1 to display
help on specific items.

--
Stefan Blom
Microsoft Word MVP


in message
news:[email protected]...
 
S

satya.mahesh

Thanks for the macro code. I did try the code and it worked well for
tables which did not have any merged cells. For tables with merged
cells it gave an error. How do we take care of such validations here?

My document has lot of tables and I want to repeat the table headers as
the tables span across pages and it is difficult to read. Some tables
have merged cells as well.

Can a macro handle these scenarios and repeat table headers for valid
tables only?
 
D

Doug Robbins - Word MVP

The following won't be as quick, but will overcome that problem

Sub MakeHeadingRows()
Dim i As Long
With ActiveDocument
For i = 1 To .Tables.Count
.Tables(i).Cell(1, 1).Select
Selection.Rows.HeadingFormat = True
Next i
End With
End Sub


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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