Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.tables
|
|||
|
|||
Detect how many pages a table is
I am using Word 2003 SP 2. Is there a way to select a table and determine
how many pages it is and return that value at my insertion (cursor) point? -- Thanks in advance! |
#2
Posted to microsoft.public.word.tables
|
|||
|
|||
Detect how many pages a table is
Robin wrote:
I am using Word 2003 SP 2. Is there a way to select a table and determine how many pages it is and return that value at my insertion (cursor) point? The following macro will display the number of pages in a message box. Sub PagesInTable() Dim startPg As Long, endPg As Long Dim oRg As Range If Not Selection.Information(wdWithInTable) Then MsgBox "Place the cursor in a table", , "Error" Exit Sub End If ActiveDocument.Repaginate Set oRg = Selection.Tables(1).Range With oRg endPg = .Information(wdActiveEndPageNumber) .Collapse wdCollapseStart startPg = .Information(wdActiveEndPageNumber) End With MsgBox "Table occupies " & endPg - startPg + 1 & " page(s)" Set oRg = Nothing End Sub Inserting the number at the insertion point is problematic -- if some text or the whole table is selected, it will be replaced by the number, which probably isn't the effect you wanted. You could collapse the Selection to its start, which would prevent that. Also be aware that the macro works off of page numbers alone. For example, if the table starts near the bottom of page 1 and ends near the top of page 2, the macro will say that it occupies 2 pages, even though it's less than one page long. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#3
Posted to microsoft.public.word.tables
|
|||
|
|||
Detect how many pages a table is
Thanks Jay, this works great! I figured out how to return the value at my
insertion point, but the problem is that if the table's page length changes, the value doesn't change. Any advice? -- Thanks in advance! "Jay Freedman" wrote: Robin wrote: I am using Word 2003 SP 2. Is there a way to select a table and determine how many pages it is and return that value at my insertion (cursor) point? The following macro will display the number of pages in a message box. Sub PagesInTable() Dim startPg As Long, endPg As Long Dim oRg As Range If Not Selection.Information(wdWithInTable) Then MsgBox "Place the cursor in a table", , "Error" Exit Sub End If ActiveDocument.Repaginate Set oRg = Selection.Tables(1).Range With oRg endPg = .Information(wdActiveEndPageNumber) .Collapse wdCollapseStart startPg = .Information(wdActiveEndPageNumber) End With MsgBox "Table occupies " & endPg - startPg + 1 & " page(s)" Set oRg = Nothing End Sub Inserting the number at the insertion point is problematic -- if some text or the whole table is selected, it will be replaced by the number, which probably isn't the effect you wanted. You could collapse the Selection to its start, which would prevent that. Also be aware that the macro works off of page numbers alone. For example, if the table starts near the bottom of page 1 and ends near the top of page 2, the macro will say that it occupies 2 pages, even though it's less than one page long. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#4
Posted to microsoft.public.word.tables
|
|||
|
|||
Detect how many pages a table is
I've seen that kind of behavior intermittently, but I can't reproduce
it at will. The ActiveDocument.Repaginate command is supposed to make sure the page numbers are stable before the .Information function runs, but it might not be completing fast enough. You might be able to fix it by inserting a delay of a second or two after the repaginate command, or maybe you can force repagination by going to Print Preview and back. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. On Wed, 3 Jan 2007 10:33:03 -0800, Robin wrote: Thanks Jay, this works great! I figured out how to return the value at my insertion point, but the problem is that if the table's page length changes, the value doesn't change. Any advice? -- Thanks in advance! "Jay Freedman" wrote: Robin wrote: I am using Word 2003 SP 2. Is there a way to select a table and determine how many pages it is and return that value at my insertion (cursor) point? The following macro will display the number of pages in a message box. Sub PagesInTable() Dim startPg As Long, endPg As Long Dim oRg As Range If Not Selection.Information(wdWithInTable) Then MsgBox "Place the cursor in a table", , "Error" Exit Sub End If ActiveDocument.Repaginate Set oRg = Selection.Tables(1).Range With oRg endPg = .Information(wdActiveEndPageNumber) .Collapse wdCollapseStart startPg = .Information(wdActiveEndPageNumber) End With MsgBox "Table occupies " & endPg - startPg + 1 & " page(s)" Set oRg = Nothing End Sub Inserting the number at the insertion point is problematic -- if some text or the whole table is selected, it will be replaced by the number, which probably isn't the effect you wanted. You could collapse the Selection to its start, which would prevent that. Also be aware that the macro works off of page numbers alone. For example, if the table starts near the bottom of page 1 and ends near the top of page 2, the macro will say that it occupies 2 pages, even though it's less than one page long. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#5
Posted to microsoft.public.word.tables
|
|||
|
|||
Detect how many pages a table is
Hi Jay
Jay Freedman wrote: I've seen that kind of behavior intermittently, but I can't reproduce it at will. [..] Thanks Jay, this works great! I figured out how to return the value at my insertion point, but the problem is that if the table's page length changes, the value doesn't change. Any advice? I guess the OP is talking about a much later changes to the table (or, as it is, a pagination reflow that would change the calculated value as well). [I'm not sure there's a good answer to that request, except running the macro again on each table prior to printing ...] 2cents Robert -- /"\ ASCII Ribbon Campaign | MS \ / | MVP X Against HTML | for / \ in e-mail & news | Word |
#6
Posted to microsoft.public.word.tables
|
|||
|
|||
Detect how many pages a table is
Hi Bob,
The behavior I saw didn't involve the value inserted in the document. I was using the macro I originally posted, with just a MsgBox displaying the number of pages. If I ran the macro on a table of, say, 2 pages; then added another page or two of new rows to the table; and reran the macro, the MsgBox still showed 2 pages. Single-stepping through the macro showed that the value returned by the line endPg = .Information(wdActiveEndPageNumber) didn't change, even after the Repaginate command. But when I ran the same test on another document, I couldn't reproduce that behavior. -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. On Sat, 06 Jan 2007 19:15:03 +0100, "Robert M. Franz (RMF)" wrote: Hi Jay Jay Freedman wrote: I've seen that kind of behavior intermittently, but I can't reproduce it at will. [..] Thanks Jay, this works great! I figured out how to return the value at my insertion point, but the problem is that if the table's page length changes, the value doesn't change. Any advice? I guess the OP is talking about a much later changes to the table (or, as it is, a pagination reflow that would change the calculated value as well). [I'm not sure there's a good answer to that request, except running the macro again on each table prior to printing ...] 2cents Robert -- /"\ ASCII Ribbon Campaign | MS \ / | MVP X Against HTML | for / \ in e-mail & news | Word |
#7
Posted to microsoft.public.word.tables
|
|||
|
|||
Detect how many pages a table is
Hi Jay
Jay Freedman wrote: [..] didn't change, even after the Repaginate command. But when I ran the same test on another document, I couldn't reproduce that behavior. Ah well: don't we all hate these "non-repro" issues! Greetings Robert -- /"\ ASCII Ribbon Campaign | MS \ / | MVP X Against HTML | for / \ in e-mail & news | Word |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
error messages when using table formula after moving column tot's | Tables | |||
I have a table that spans multiple pages. | Tables | |||
Table breaks accross two pages - even though it is instructed not | Microsoft Word Help | |||
reformat table onto multiple pages | Tables | |||
How do I set up a table title so that across pages it adds "cont'd | Tables |