Extract header and footer and place into body?

G

Geoff C

Hi, can anyone help? I'm trying to fix some RTF output from SAS.

In each page of the output files there is a table in the header, a table in
the body, and a table in the footer. Each subsequent page is in a different
Section.

All I need to do is taken the tables from the header and footer, place them
in the appropriate position around the body table (not connected) and move to
the next page. However this is proving more tricky than I thought it would
by just recording it, since sometimes (not always) the body table is long
enough to force a new page when the header is pasted at the top.

I'm no VBA expert, especially in Word, so is there anything easyish that
would help with this?

Many thanks,
Geoff
 
S

StevenM

To: Geoff C,

I don't know what SAS is. But looking at the rest of your description, it
would seem that your problem is simply that you need to modify the top &
bottom margin of your document. I would assume that is the reason you don't
have enough room to put the header & footer tables into the body of the
document.

Perhaps something like this will work.

Sub MoveTablesFromHeaderFooter()
Dim i As Long
Dim oRange As Range

With ActiveDocument
For i = 1 To .Sections.count
.Sections(i).Range.Tables(1).Range.Cut
Set oRange = .Sections(i).Range
oRange.Collapse CollapseStart
oRange.InsertParagraph
oRange.InsertParagraph
oRange.start = oRange.start + 1
oRange.Paste

..Sections(i).Headers(wdHeaderFooterPrimary).Range.Tables(1).Range.Cut
Set oRange = .Sections(i).Range
oRange.Select 'temp
oRange.End = oRange.start
oRange.Select 'temp
oRange.Paste

..Sections(i).Footers(wdHeaderFooterPrimary).Range.Tables(1).Range.Cut
Set oRange = .Sections(i).Range
oRange.start = oRange.End
oRange.InsertAfter vbCr
oRange.start = oRange.start + 1
oRange.Paste
' A "Pica" = 1/6th of an inch
.Sections(i).PageSetup.TopMargin = PicasToPoints(1)
.Sections(i).PageSetup.BottomMargin = PicasToPoints(1)
Next i
End With
End Sub

Steven Craig Miller
 

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