What is the fastest way to determine if a table spans two pages?
how do i get a table to continue over 2 pages?
table continued on next page
allow row to break across pages not working
excel table in word over multiple pages
table borders when table is split across pages
how to make a multi page table in word
how to make a table continue to next page in word
The initial problem that led me to learn VBA is as follows:
You have a table that can be up to 10,000 rows (several hundred pages) long in a Word document. The table has a title in the form of a paragraph above the first row. This title is styled such that it links to a Table of Contents (
Style = "Caption"). The table must be broken at the last row on each page, and the title must be inserted before the new table but in a different style that is not linked to the Table of Contents(
Style = "Caption Cont").
The first page will look like this:
The second page will look like this:
My first solution was relatively hackey and not at all elegant. I've managed to put together the following solution that works quite well. However, the initial process of determining the row number at which the table crosses pages is pretty slow due to the use of
Range.Information. I'm wondering if there's a faster way to determine the bottom row on the page.
Putting the document into
wdNormalView shaves off about a second per page, even with
Application.ScreenUpdating = False...
The program requires that your cursor is somewhere inside the table, which is fine and not a functionality I wish to remove.
It currently does about 120 pages per minute, with the majority of the time being spent on determining the row to split at (i.e.
splitNum). I'm sure it can be much faster with a different method of determining
I CANNOT ADD AN ADDITIONAL ROW TO THE TABLE FOR THE PURPOSES OF USING "REPEAT HEADER ROWS". It would violate regulations that are enforced in my industry, and a non-conforming document can be a huge hit to the company and future business
Sub tblSplit() Dim timeCheck As Double Application.ScreenUpdating = False Application.ActiveWindow.View = wdNormalView timeCheck = Time On Error GoTo ErrH Dim crossRef As Range, delRange As Range, tblR As Range, newTbl As Range Dim tblNumField As Range, tblNum As String Set tblNumField = Selection.Tables(1).Range tblNumField.MoveStart wdParagraph, -1 tblNum = tblNumField.Words(2) Set crossRef = Selection.Tables(1).Range Set thisTbl = Selection.Tables(1).Rows(1).Range Set tblR = Selection.Tables(1).Range
Insert cross-reference to title with style "Caption Cont"
crossRef.Move wdCharacter, -2 crossRef.InsertCrossReference ReferenceType:="Table", ReferenceKind:= _ wdOnlyCaptionText, ReferenceItem:=tblNum, InsertAsHyperlink:=True, _ IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" " crossRef.Text = vbCr & " (Cont.)" & vbTab crossRef.MoveStart wdCharacter, 1 crossRef.Style = "Caption Cont." crossRef.Collapse wdCollapseStart crossRef.InsertCrossReference ReferenceType:="Table", ReferenceKind:= _ wdOnlyLabelAndNumber, ReferenceItem:=tblNum, InsertAsHyperlink:=True, _ IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" " crossRef.MoveEnd wdParagraph, 1
Delete duplicate title
Set delRange = crossRef.Duplicate crossRef.MoveEnd wdParagraph, 1 crossRef.Copy delRange.Text = vbNullString
Find row at which table spans two pages
Dim splitNum As Long, n As Long, i As Long, pageNum As Long pageNum = tblR.Rows(1).Range.Information(wdActiveEndAdjustedPageNumber) i = 15 Do If tblR.Rows(i).Next.Range.Information(wdActiveEndAdjustedPageNumber) <> pageNum Then splitNum = i Exit Do End If i = i + 1 Loop Until i = 100 'arbitrary cap to prevent infinite loop n = 1
Split and format
Do DoEvents 'Split and format tblR.Tables(n).Split (splitNum) tblR.Tables(n).Rows.Last.Borders(wdBorderBottom).LineStyle = wdLineStyleSingle 'Paste the stuff Set newTbl = tblR.Tables(n + 1).Range newTbl.Move wdParagraph, -2 newTbl.Paste newTbl.MoveEnd wdParagraph, 1 'Clear excess newTbl.Paragraphs.Last.Range.Text = vbNullString 'Next n = n + 1 Loop Until tblR.Tables(n).Rows.Count < splitNum
Restore state, report time, safe-exit and error handler set-up for debugging
Application.ActiveWindow.View = wdPrintView Application.ScreenUpdating = True MsgBox "Pages completed: " & n & vbCr & _ "Time (sec): " & DateDiff("s", timeCheck, Time) & vbCr & _ "Seconds per page: " & CDbl(DateDiff("s", timeCheck, Time)) / CDbl(n) & vbCr & _ "Pages per minute: " & n / DateDiff("s", timeCheck, Time) * 60 Exit Sub ErrH: Application.ScreenUpdating = True Err.Raise Err.Number Stop End Sub
Here is a workaround that makes it seem as if the paragraph is separate from the table, but it's really the first row. I created a table of data with a couple hundred rows, then inserted a new row on the top of the table. The paragraph goes into this empty row at the top. Assuming the rest of the table has borders enabled, disable the top, left, and right borders for the first row only. Then enable "repeat header row". It looks like this when you're done:
and then the second page:
How to Make a Table Spread Across Pages in Microsoft Word , Microsoft Word includes layout options to divide a table across two or more pages. For example, if the rows refer to multiple regions, you can divide the table to The divided sections include a Table Move Handle icon for quick placement on Click to add a tick in the check box next to "Allow row to break across pages"� When you have a Word table that spans multiple pages, you'll probably want the header row to appear at the top of each page. Luckily, repeating a heading row across several pages takes only a few
The fundamental problem you will have with any table-splitting approach is that it doesn't take account of the fact that Word uses the active printer driver to optimise the page layout.
Consequently, you may end up with what appears as the last row on a page when one printer is used ending up at the top of the next page when another printer is used. Alternatively, your headings might end up at the bottom of the page when a another printer is used.
As for your 'Caption'/'Caption Cont' Style machinations, that is all quite unnecessary if you create a full-with row for the caption at the top of the table and mark both the first and second rows as table header rows. Only the entry at the top of the table will appear in the Table of Contents. No code required.
Control Page Breaks in Tables - Word FAQ site, How do I control where the page breaks will fall in a table that extends over several and you cannot select a column in the entire table since it is now two tables. First, check that you don't have all the rows in your table set to “Keep with next. Unless you have a very good reason for wanting to have text wrapping on� This is the easiest way to determine allowable dead loads, live loads and deflection limits. This publication has a much more extensive offering of possible joist and rafter conditions. Once you find the appropriate table in the book, you determine acceptable Fb and E values for your particular span condition.
This can be done in a much simpler way by inserting the copy of the table caption in a row at the top of the second part of a split table.
- Split the table at the end of the first page as you already do. The rest of the activities now focus on the second part of the table.
- For the second part of the table insert a single row at the top of the table.
- Make the new single row a repeating table heading.
- Paste the copy of the table caption in the row at the top of the second part of the table.
This will achieve the effect you are trying to achieve.
How to Stop a Table Row from Splitting Over Two Pages (Microsoft , Word allows you to format the table so that rows stay together and don't split. How you do the How to Stop a Table Row from Splitting Over Two Pages. by Allen Wyatt Make sure the Allow Row to Break Across Pages check box is cleared. Click your Quickly Displaying the Font Dialog Box � Using MPF� I have a table that takes up a full page, but I want it to start on a page that already has some text and then continue onto the next page (i.e. it's ok if the table gets broken up and spans two pages). It is a simple two column table:
APA Style 6th Edition Blog: Table Tips, by Stefanie Tables are a terrific way to share, compare, and contrast data. If you have written a dissertation or report for class, check with your says that you can't have one, a table sounds like a good idea to me. Hello! For long tables ( spanning multiple pages), where should we include the Note? In the Table Properties dialog, choose the Row tab. Check that the dialog says Rows 1-x (where x is the number of rows in your table). In the example below the table being edited has 44 rows. Deselect the option to Allow rows to break across pages. This will apply to all 44 rows in my example table. Click OK.
4 ways to control page breaks within tables and table styles (for , It determines whether the individual rows in a table may break across a page. then Word will split the table across two pages, with rows breaking according to� I have a Table (multiple rows, multiple columns, see below ) that is longer than one page. How can I tell LaTeX to continue on the next page. Adding a ewpage didn't work; Manually 'ending' and 'reopening' the table works, but is very tedious, since the table will be many pages long.
Table Setup - APA Style, This page addresses the basics of table setup, including table components, principles of table construction the use of borders and how to handle long or wide tables), and placement of tables in the paper. Note that tables and figures have the same overall setup. View the sample tables to see these guidelines in action. Full code for “Table with header cells in the top row and first column” Table with an offset column of header cells. In this table, the row header cells are in the second rather than in the first column. The approach is similar to the examples above: The scope of the header cells in the top row is set to col.
- What about repeating the table header row(s)?
- @PeterT the actual title of the table is not in the header row, it is a separate paragraph. I cannot share a screenshot due to the nature of the document, but think of it as a paragraph of text before the table that is not technically associated with the table as far as VBA is concerned.
- since this code is working and you just really want more speed, maybe you can also post on Code Review. Maybe somebody there can take a crack at improving the speed.
- I appreciate the effort, but the document gets converted to PDF and has to meet stringent requirements set forth by governmental regulatory bodies. I unfortunately can't use any formatting "tricks" that change the innate structure of the document. They are required to be separately titled and titled in specific formats. Plus, there is actually a header row as well as the title. Both need to be repeated. Let me see if I can create a mock-up and edit my question.
- The document is configured such that the margins are standard across the machines. Moreover, everyone uses the same printer and therefore has the same driver. As stated in a response to nearly everyone who offered this as an option, creating a faux-header for the purposes of repeating header rows is not an option. I cannot do that because it would violate regulations that are enforced in my industry, and a non-conforming document can be a huge hit to the company and future business.
- This doesn't achieve the uniformity that splitting the table does, nor does it allow for the actual header row associated with the table to be repeated across pages. I realize I probably wasn't explaining it well, so I edited my post to include some mockup screenshots that may be helpful.
- Those objections are quite trivial and easily resolved with a little bit of additional coding.
- how is this comment helpful?
- It tells you that you are very close to a solution to your problem but not getting there because you give up at the first hurdle. The small amount of additional code is to copy your repeating headers to the second part of the table before adding the single row to contain the copy of the caption. Some code to turn off the top and left/right borders of the single cell, and then a small amount of code to make sure the second part table alignment matches that which you show in your updated question.
- I'm aware of the ability to manipulate margins, as well as how to do a copy and paste, thanks. Neither your solution nor your additional input to "trivially" resolve the objections meet my goal, which is to split the table and insert the title in paragraph form. The task needs to be completed within organizational and regulatory parameters. If those requirements weren't in place, I would not even bother with splitting the table, and just repeat header rows. Maybe instead of saying that I give up at the first hurdle, you should look more carefully at the actual obstacle.