I have a VBA macro that cleans a 2010 Word document. Actually, it removes empty rows on many tables.

At the end of the function, I would like to create a table of contents with the titles and page numbers of all tables in the document.

Dim tTable As Table
tTable.Range.Information(wdActiveEndPageNumber)

The problem is, cleaning the tables reduced the length of the document from 30 pages to 25 pages. When I call .Information(wdActiveEndPageNumber) the page indexes have not been updated yet.

I tried to call Sleep for a while but it doesn't work either.

I'm not a VBA specialist, but is there a function to force update the page numbers of a document?

Thanks

有帮助吗?

解决方案

After some research, I found the function to call:

ActiveDocument.Repaginate

It seems to work fine!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top