Split table on each page, move document header/footer into document

S

Susan Parker

Can I do this?

Word 2000 on Windows 2000 Pro.

We have Word tables that are created with SAS as RTF. The long and
short of what we need to do is pull the document header and footer
into the body of the document, but we have a table that spans perhaps
several pages and so, we need to split the table onto each page. The
column headings are automatically repeated at the top of each page.
So I want to split the table, but keep the column headings with each
split part.

I'm trying to do all of this with VBA, so we can build it into a
template and automatically process each document.

Any suggestions are greatly appreciated.

I think if I knew what collection to cycle through (since there is no
page collection) or how to test that I'm at the top of the document or
at the bottom of the document, that I could make some progress.

I also think I need to start splitting the table starting with the
last page and working my way backward, so as to preserve the rows of
the table that are on each page already. That way I should have
sufficient room to put the table headings on the page and should also
be ok for room when I pull the document header and footer into the
body of the document.

Thanks!

Sue
 
D

Doug Robbins

Have you considered the option of inserting a row at the top of the table
(that will also become a header row and be displayed on every page, and then
inserting into that row the information from the document header.

If that will do what you want, it will be a lot easier.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
S

Susan Parker

Hi Doug!

Thanks for your reply!

I definitely want what is easiest. The document header and footer are
also tables (that's what we get for wanting to left justify part of it
and right justify another part) and it has a different shape
(different number of columns) than table in the body of the document.

Probably a stupid question, but will the page x of y fields we
currently have in the document header still work if we move them into
the table header? Basically, we need for each table to be page
numbered and then the medical writer will use the document footer to
page number the whole document. Does this make any sense?

Sue
 
D

Doug Robbins

You can have a "repeating header that consists of rows with different
numbers of columns, overall width etc. and the Page x of y will work where
ever you put it.

I haven't worked out what the following means:

"Basically, we need for each table to be page numbered and then the medical
writer will use the document footer to page number the whole document. "

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
G

Guest

The tables we produce will go into a larger document. We
like for each of the tables to have their pages numbered
(what I called page numbered) so you know what page of
table x you're on. We'll unfield the page x of y fields
within each table, so they won't change. Then when the
larger document is put together by our medical writer, then
entire document will have its pages numbered.

Let me play with putting the page header onto the table and
doing the page x of y fields and see if the page numbering
works out.

This leaves putting the current document footer into the
body of the document. I think this brings me back to my
original problem. How do I split the table on each page?
I couldn't quite figure out a good method of "paging up" in
VBA. I tried wdWindow for the unit and it wasn't always
successful in paging up. Even if I had been successful, I
don't know how to check to see if I'm at the top of the
document so that I can stop paging up.

Thanks!
 
E

Ed

Susan:

I have a macro that splits a table at the end of a page, pastes in your
header rows into the new table, then splits and pastes again until the last
page. I'm not an expert, so it could probably use some tweaking, but it
works for me. The only "gotcha" is you must select and copy the header rows
you want repeated. The MsgBox that pops up was a reminder to myself to set
things up right before starting; otherwise, I'd have to undo 80-odd pages of
tables and start over! When I use it, I have to split the table at page 2,
repeat the header rows and put "(Continued)" in it, and then copy the new
header rows. If none of this applies, feel free to delete it. Answering
NO, though, because I had forgotten gave me a convenient way to restart the
macro.

Hope it works for you.
Ed

Sub DoAppxBtbl()
'
Dim CurDoc As Document
Dim cntPages As Integer
Dim PgNo As Integer

If MsgBox("Have you:" & vbCr & _
"-- copied header rows into Pg. 2 table?" & vbCr & _
"-- put (continued) in the header row?" & vbCr & _
"-- copied *ALL THREE* new header rows?", vbYesNo) = vbNo Then
Exit Sub
End If

Application.ScreenUpdating = False

Set CurDoc = ActiveDocument
cntPages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
PgNo = Selection.Information(wdActiveEndPageNumber)
PgNo = PgNo + 1

' **LOOP*
Do

' Go to next page
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, _
Count:=PgNo

' Must be in table
If Selection.Information(wdWithInTable) = True Then

' Go to previous line
Selection.MoveLeft Unit:=wdCell, Count:=14, Extend:=wdMove

' Split table and insert header rows
Selection.SplitTable
Selection.InsertBreak Type:=wdPageBreak
Selection.Paste
Selection.Delete Unit:=wdCharacter, Count:=1

' Update page count
cntPages = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)

' Increment PgNo
PgNo = PgNo + 1

ActiveDocument.Save

Else: Exit Do

End If

Loop Until PgNo > cntPages

Application.ScreenUpdating = True

End Sub
 
S

Susan Parker

Sorry my last post was anonymous. Didn't notice the other
part of the form since I'd been posting through Google Groups.

Thanks Ed!

I will give it a go and post any findings

Sue
 

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