DifferentFirstPageHeaderFooter & documents

samsmithnz

Well-known member
Joined
Jul 22, 2003
Messages
1,038
Location
Boston
Im trying to use the DifferentFirstPageHeaderFooter property to create a word document programmatically in VB.NET, but I cant seem to work out how to do it. Can anyone help?
 
Let me jsut rephase that question. Has anyone had problems setting the DifferentFirstPageHeaderFooter property before? The following code just isnt working, its not adding a new header... in fact no headers show up at all...


objDocument.PageSetup.DifferentFirstPageHeaderFooter = -1
 
That command is working. You can look in the Alt|File|PageSetup... and then the Layout tab to see that it is. However, this by itself does not add any Headers.

Im no good at Word and so do not have a clue how to actually add a Header programmatically. I would probably make a template and save it for later use rather than actually make the headers via code, but thats just because Im bad at Word. :(

To learn how to do it programmatically, I would try using the Macro Recorder and or make use of the Object Browser and Help Files...

Sorry I cant do better, but I just really dont know the Word Object Model well at all. Hope this helps at least a little?

-- Mike
 
Thanks Mike, Id already done that. It turns out I had to get my order correct. I had to set the main header first, then the firstpage property and THEN add the first page header for it all to work.

Cheers
 
Hey Sam,

I *think* I understand...

Would you mind showing that code?
Id like to see what you mean exactly...

-- Mike
 
Certainly, here you go:

Code:
                Headers & Footers
                the headers/Footers are messy. Because we are pasting in, we only have one go at them, 
                so only one paste per header/Footer. Also the order is VERY important.
                1. Add general document header
                2. Set the DifferentFirstPageHeaderFooter property. Note that if we set this before step 1, it gets reset to 0/false.
                3. Add the 1st page header

                Add the general Header and footer, and the general page numbers
                PasteData(objDocument, strCaseEndHeader, modMain.ePasteLocationType.ePasteHeader)
                PasteData(objDocument, strConfidentialText, modMain.ePasteLocationType.ePasteFooter)
                objDocument = AddPageNumbers(objDocument, Word.WdSeekView.wdSeekCurrentPageFooter)

                now set the property and add the 1st page header and footers and the 1st page page numbers
                objDocument.PageSetup.DifferentFirstPageHeaderFooter = -1
                PasteData(objDocument, strCaseEndHeader1stPage, modMain.ePasteLocationType.ePasteHeader1stPage)
                PasteData(objDocument, strConfidentialText, modMain.ePasteLocationType.ePasteFooter1stPage)
 
Note that a lot of the code Ive posted above calls custom functions using custom enums, etc, but you get an idea of the solution to my problem.
 
Ok, that is very nice. :)

Thanks for explaining it so well, I really appreciate it...

-- Mike
 
Back
Top