Word header/footer woes.

D

Dirk Frulla

Hello!

I am attempting to automate a Word document merge. I am using Visual Studio
2005 and Word 2007, although I tested it with Word 2003, and the issue
exsists there as well.

The purpose of the program is take a series of Word documents and combine
(by combine, I mean concatenate) the documents into one large Word document.
Most of the time, there are roughly 500 documents to combine. However, it
sometimes need to concatenate over 2000 documents.

I have been successful creating a program for this - EXCEPT for one little
snag - header size. My main strategy is to create one master Word document,
and then insert blank page sections into the document, open the documents to
be merged, copy the content to the clipboard, and then paste (using source
formatting) the content into the new section of the master document. As I
mentioned, it works fine, and I've been able to re-number the headers and
everything. The problem is the header SIZE.

Here are some steps to duplicate the issue directly out of Word:
1) Open new Word document.
2) Type something, anything in the main section of the first page.
3) Switch to header/footer mode (edit the header)
4) Type something in the header, doesn't matter what it is.
5) Close header view

At this point you should ONE page with a header.

6) Insert a new PAGE BREAK SECTION at the end of the document. Word, by
default, carries the header down to this next section, so you should have the
same text in the header of this new section.
7) Switch to header/footer view again.
8) "Uncheck" the "Link to Previous" button. This should unlink the header
from the previous section.
9) Click the "Go to Footer" button and uncheck the "Link To Previous" button
for the footer.

Now that the header and footers have been unlinked you can delete the
content of these headers without deleting the content in the headers of the
prevous section.

10) Click "Go To Header" and delete the content in the header.
11) Close header/footer view. At this point you should have 2 pages, the
second of which is in a separate section, with no content in the
headers/footer (they are unlinked), and the first page should look exactly
how you first composed it.
12) For the second section (caret blinking in main part of second section) -
Edit the margins. Adjust ALL margins to 0.25 inches.

And this point you should be able to see the issue. The section section is
prevented from having a 0.25 in. margin because the header size is 0.5 in.,
even though they are unlinked and there is NO CONTENT in them.

Anybody have any insights on this? Is there a way to .... well ... "reset" a
section so that it is completely indepenent of the other sections?

Thanks!
Dirk Frulla
 
A

Andrei Smolin [Add-in Express]

Hello Dirk,

The following VBA code returns the same value for the margins of the second
section:

Dim sec1 As Word.Section
Set sec1 = ThisDocument.Sections.Item(1)
Dim sec2 As Word.Section
Set sec2 = ThisDocument.Sections.Item(2)
Debug.Print sec1.PageSetup.BottomMargin, sec2.PageSetup.BottomMargin
Debug.Print sec1.PageSetup.TopMargin, sec2.PageSetup.TopMargin
Debug.Print sec1.PageSetup.LeftMargin, sec2.PageSetup.LeftMargin
Debug.Print sec1.PageSetup.RightMargin, sec2.PageSetup.RightMargin

Visually, I see the same result as you do.

Andrei Smolin
Add-in Express Team Leader
www.add-in-express.com
 
D

Dirk Frulla

Andrei,

Thanks for the response. That is exactly correct. The issue is even more
pronounced if you set the margins to 0. No matter what I try, I can't get
that header to go away. I have been doing some searching and found only a few
other articles/posts about this. One person said that switching to print
preview and then back to print view will cause Word to re-adjust the headers,
however, when I tried it, it did not work.

It seems very odd. Once you edit a header, it exists, and once it exists, it
takes up the standard 0.5 inches at the top of the page - even if there is no
content on the page.

There is an exception to this. If you open Word, and edit the header in the
main section, close the header view, set the section's margins to zero, and
THEN go back in and delete the content of the header, it shrinks back -
BUT!!! - this only seems to work on the first section. All other sections
after this do not shrink back. It is very frustrating.

Thanks,
Dirk
 

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