question about word automation(how to insert header)
hello
i am trying to develope an application for word automation.the application should generate a word document and need to insert a header into document.i have find the code from msdn and it works well.but i can't insert header.(i have found the code for inserting header from msdn too) but it doesn't wrok
this is the code i user for header:
foreach (Word.Section sectionin oDoc.Sections)
{
object fieldEmpty = Word.WdFieldType.wdFieldEmpty;
object autoText = "HELLO THIS IS HEADER";
object preserveFormatting =true;
//section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text
section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields.Add(
section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range,
ref fieldEmpty,ref autoText,ref preserveFormatting);}
and when i run it,it write an error instead of header in header section. this is the error:
Error! Bookmark not defined.
dose anybody know how to insert header automatically?
any information is appreciated
Regards
Bluestar

