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

[2979 byte] By [bluestar] at [2007-12-23]
# 1
Hi Bluestar
Notice that you're posting in a VBA forum. You're working in C# (.NET
Framework). The better place to ask Office automation questions when
your language is not VBA is
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.of
fice.developer.automation&lang=en&cr=US
<http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.o
ffice.developer.automation&lang=en&cr=US>
When you post there, please include what kind of information are you
trying to insert into the Header. Right now, you're inserting a field
code, but what you're putting into the field code is invalid. It's
difficult to determine exactly what you want to have. Your basic
approach is correct, it's just this last little step...
CindyMeister at 2007-8-30 > top of Msdn Tech,Microsoft ISV Community Center Forums,Visual Basic for Applications (VBA)...