Tables in headers

R

Raphael Goubet

Hi,

If I have a table in the header of a document, they are not included
in the Tables collection. I.e, if I run the following loop, whatever
action it contains won't be applied to the tables in headers:

Dim MyTable As Table
For Each MyTable In ActiveDocument.Tables

[...]

Next MyTable

Why is that?

Raphaël
 
D

Dave Lett

Hi Raphael,

Word uses story ranges, and the Header/Footer is in a different storyrange
than the main text. Therefore, when you cycle through the tables in
ActiveDocument.Tables, you're cycling through the tables in the Main
storyrange.

To access a table, you have to identify the section and the header/footer.
Or, you could cycle through all the story ranges, and then the tables in
each storyrange, as in the following:

Dim oTbl As Table
Dim oStry
For Each oStry In ActiveDocument.StoryRanges
For Each oTbl In oStry.Tables
Debug.Print oTbl.Rows.Count
Next oTbl
Next oStry

HTH,
Dave
 

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