Log in

View Full Version : Working with Header



Mavila
05-15-2017, 09:48 AM
I'm creating a single document (target) from multiple separate documents (source). I've been using Selection.InsertFile but the formatting of the text is inconsistent. So, I'm going back to copying and pasting the source document contents into the target document.

After each source is pasted into the target, I create a SectionBreak(Next Page). Each section has a header and footer, first page different. The first page header is the title of the source. The second page header is a shape (shaded line). The footers aren't problem.

The target ultimately is constructed by 40 or 50 source documents depending upon the user's needs. It works fine, EXCEPT (there always seems to be an exception) on 2 or 3 of the source documents. When the SectionBreak is inserted, the shaded line is carried over onto the first page of the next section - I can't turn off "LinkToPrevious" until after the SectionBreak is inserted. This isn't a problem because when the new source is pasted (it's copied via selection.wholestory, selection.copy) the shaded line is removed/overwritten.

EXCEPT for these 2 or 3 source files. The line remains. I've tried deleting the line with activedocument.sections.last.headers(wdheaderfooterfirstpage).shapes(1).del ete, activedocument.sections.last.headers(wdheaderfooterfirstpage).range.delete, activedocument.sections.last.headers(wdheaderfooterfirstpage).range.select then selection.delete.

I thought maybe the source file was read only, but that's not the case.

It's as if I can't even get access to the header no matter what I do. It won't even let me insert text into the FirstPage header. It's like it's locked. I'm stumped.

Any ideas what might be going on here?

Mavila
05-16-2017, 09:42 PM
I give up.

macropod
05-16-2017, 11:53 PM
Judging by your various posts on this general subject, it seems you haven't really taken the time to understand how Word works before rushing in and now you're encountering problems.

First and foremost, you should base all documents on the same template and use the same Style definitions for their content - consistently. That way the formatting will be consistent in each document and will remain consistent when the documents are combined. Trying to combine documents with different definitions for the same Styles, and/or those Styles used inconsistently (which includes overwriting them with direct formatting) is a recipe for disaster. Headings, for example, should be created using the appropriate Heading Styles. Do that and your Table of Contents in a given document will auto-generate.

If you're going to combine the documents, you should consider giving the range spanned by the TOC for each document a unique bookmark name (e.g. Chapter1, Chapter2, etc.) so there are no bookmark conflicts when the documents are combined; otherwise you'll end up with the TOCs in the combined document all unhelpfully referencing the entire document.

As for headers & footers, the most appropriate way for handling the content depends on what you're trying to achieve. For example, if you're trying to replicate a given heading for each Chapter, you might only need to use a single StyleRef field in a common header to achieve that. You may not even need Section breaks between them. Otherwise, you might need the Section breaks and to unlink the headers/footers for each Section from the previous one before inserting each Section's header/footer content.

FWIW, I've produced manuals in the past with ~40 chapters, each with an individual TOC, page headers, etc. and an overall TOC for the manual as a whole. Approached with suitable planning it's not at all difficult to do.