PDA

View Full Version : Setting Header and Footer LinktoPrevious = false



fionabolt
06-01-2007, 02:29 AM
I have developed a tool to add a letterhead to a previously typed document. (2003). This inserts all the usual letterhead info into the header and footer of the first section wdHeaderFooterFirstPage, and then different info into the footer of the following pages (by looping through all the storyranges).

I have set "ActiveDocument.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True" and if the previously typed document has multiple sections, then I can set the second section wdHeaderFooterFirstPage linktoprevious = false. No problem so far.

My issue comes if the previously typed document had only one section when the user initially uses the tool to add the letterhead, and then subsequently edits the text adding a new section. Because linktoprevious defaults to true the newly created section contains all the same header information as the firstpage of the first section.

Is there a way that I can change the default linktoprevious to false?

Where the previously typed document has only 1 section I have tried inserting a temporary sectionbreak setting linktoprevious=false and then deleting the section break. However, the default reverts to true again.

Any ideas would be gratefully received.
Thanks

fumei
06-01-2007, 01:30 PM
You can NOT set the default LinkToPrevious as False. It is the default. Sorry. You simply have to deal with it.

Any new Section has ALL of the headers and footers as LinkToPrevious = True.

I would love to be able to set the default to False. This is why I use my own Insert Section Break procedure. It takes care of this rather anoying "feature".

fionabolt
06-04-2007, 12:23 AM
Fumei

Thanks for that.

When you say "This is why I use my own Insert Section Break procedure. It takes care of this rather anoying "feature"." Do you add a new toolbar, or is there a class module that you can override the word dialog for insert break?

Regards,

fumei
06-04-2007, 08:54 AM
I built a userform with all the Insert Break options normally available (Insert > Break) but with added logic.

If I select Section Break (either Odd, Even, Next) the userform expands to show a Yes/No option "Keep As previous?). If Yes, it checks the state of the previous Section. If there are any Different (ie. FirstPage, Odd/Even) it further expands to let me check the ones I may(or may not) wish to Keep.

That is, if the previous section had DifferentFirstPage, I can choose to Keep As previous that one, but not Keep the other two (ie. Primary, and EvenPages).

The userform simply allows me to make ALL possible choices.

When I click OK, it makes the Section Break I chose, automatically makes three new pages, sets the header state for them as I checked them, then deletes the pages.

Once headers/footers are set for a section the contents are persistent. So creating the pages (blank) and making the appropriate header/footer states, keeps them. Deleting the pages does NOT remove the header/footer for them. Now when I add text and to the first page of the Section, and a new page is made, the header will ALREADY be the proper one.

This is one of the issues/problems with LinkToPrevious = True being the default. You make a new Section, put in text and it goes beyond the first page - thus making a new page - IF you have DifferentFirstPage, or DifferentOddEeven, in the previous section, the new page will automatically be SameAsprevious...and usually....wrong.

So, when I make a new Section I immediately explicitly make three new blank pages, explicitly make them NOT SameAsPrevious, then delete them. These are, again, stored and persist. Additional pages added into the section will use THEM.

I call the userform with a keyboard shortcut, as I use the keyboard a lot.

BTW: as my most common task (for a lot of documentation) is a Section break for a new chapter/module with certain actions, I have a separate keyboard shortcut to do THAT task. The userform is only called when I need full access to ALL possibilities.

My "common" Section break macro does the following:

- make a Section break Odd page
- make three new blank pages
- explicitly set the new Section as DiiferentFirstPage, DifferentOddEven
- explicitly set FirstPage as LinkToPrevious = True (the Chapter opening page has no header, for all of them, so I can keep them the same)
- explicitly set the other two (Primary, EvenPage) as LinkToPrevious = False
- explicitly set the range contents to be blank
- explicitly put the Title into the header (EvenPages as it is first after FirstPage), picking up the Title from the Title properties, applying HeaderTitleEven style to it
- so far, nothing has been displayed, this happens behind the scenes, but now a simple InputBox displays asking for chapter/module name. This stored as a string variable.
- explicitly take that variable and put it in the EvenPage header applying the HeaderChapterEven style to it
- explicitly insert that variable into the body iof the document at the start of the section, applying the ChapterTitle style
- explicitly put the Title into Header Primary and apply HeaderTitleOdd style to it
- explicitly put the variable (chapter name) into Header Primary and apply HeaderChapterOdd style to it.
- delete the blank pages.

So, with a keyboard key, I get one inputbox asking me for the new chapter name. All the formatting, setting up of the new Section gets done with that one input. The new Section is properly set up with LinkToPrevious where appropriate (the first page) and NOT linked where appropriate (everything else), with the contents of the headers completed, AND the chapter title inserted in the body of the text. With one action.

Simple.