Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

- I have a template in Word 2007 with a header/footer.
- I have a word document (2007)
- I open the word document and attach the template (with C#)
- The header/footer does not show up

Anyone know why? Is it not supposed to appear? (It does not show up when I try to do it in Word, either)
(The character-styles are updated, though. Just not the header/footer!)

Regards,

VJ
Posted

i don't know if in template file the header adn footer add corectly.
any way i used this code to add header and it wroked with me
but i didn't tried to attach the file
but any way i hope this code to be useful to u .
//
//EMBEDDING LOGOS IN THE DOCUMENT

//SETTING FOCUES ON THE PAGE HEADER TO EMBED THE WATERMARK

oWord.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader;



//THE LOGO IS ASSIGNED TO A SHAPE OBJECT SO THAT WE CAN USE ALL THE

//SHAPE FORMATTING OPTIONS PRESENT FOR THE SHAPE OBJECT

Word.Shape logoCustom = null;



//THE PATH OF THE LOGO FILE TO BE EMBEDDED IN THE HEADER

String logoPath = "C:\\Document and Settings\\MyLogo.jpg";

logoCustom = oWord.Selection.HeaderFooter.Shapes.AddPicture(logoPath,

ref oFalse, ref oTrue, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);



logoCustom.Select(ref oMissing);

logoCustom.Name = "CustomLogo";

logoCustom.Left = (float)Word.WdShapePosition.wdShapeLeft;



//SETTING FOCUES BACK TO DOCUMENT

oWord.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;
 
Share this answer
 
Thanks alot dabbourabd!

That code did what I wanted.

The only problem now is getting it to work when attaching templates. :confused:

(Imagine 50 people all having a template called "default.dotx",
when the document opens the template should be attached and the document be formatted differently for all users X| )
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900