Header row is not repeated on the following pages automatically if filling the table with VBA

In a Word template, I have a table template consisting only of a header row, with "Allow row to break across pages" unset and "Repeat as header row at top of each page" set:

tablerow settings

In a VBA script (from Excel via Word.Application if that matters), I add many data rows like the following, so that the table becomes larger than a page:

Dim table as Word.table
Set table = <get the table>
Dim data()
data = Array("a", "b", "c", "d", "e")
Dim r As Word.row, i, j As Long
For j = 1 to 100 Set r = table.Rows.Add() For i = 0 To UBound(data) r.Cells.Item(i + 1).Range.Text = data(i) Next
Next

The data rows appear fine but the header row is not repeated on the following pages despite the setting.


The solutions found on the Net say the following:

4

1 Answer

This is a bug, most probably. I've seen it from Word 2007 all the way to 2016.

This is a workaround that I've found:

'Headings do not start replicating themselves on further pages automatically
'even though they should.
'Have to force their reformat manually.
Application.ScreenUpdating = False
table.Rows(1).HeadingFormat = False
Application.ScreenUpdating = True
table.Rows(1).HeadingFormat = True

All the operations are required, as is the order. Otherwise, there's no effect.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like