Hi Guys,
I've been going mad trying to get this to work - there seems to be very little c# resource available on these Office libraries.
Anyway I'm trying to update a Word document to insert autotext into the footer of a document - the "page x of y" autotext entry. I can get the autotext to be entered into the footer but it will overwrite any existing text that is already present in the buffer.
This is (a summary of) my existing code:
//Add Page Numbers
Word.Document docWord;
Word.AutoTextEntries docAutotextEntries;
Word.AutoTextEntry docAutotextEntry;
Word.Section wordSection;
docWord = WordApp.ActiveDocument;
docAutotextEntries = WordApp.NormalTemplate.AutoTextEntries;
object indexitem = 26; //page x of y
docAutotextEntry = docAutotextEntries.get_Item(ref indexitem);
object dirstart = Word.WdCollapseDirection.wdCollapseEnd;
object richtext = true;
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.InsertAfter("\r");
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Collapse(ref dirstart);
docAutotextEntry.Insert(wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range, ref richtext);
I've also tried using the range.fields.add method, instead of the above, and the same thing happens.
Any ideas would be greatfully received! Thanks.
I've been going mad trying to get this to work - there seems to be very little c# resource available on these Office libraries.
Anyway I'm trying to update a Word document to insert autotext into the footer of a document - the "page x of y" autotext entry. I can get the autotext to be entered into the footer but it will overwrite any existing text that is already present in the buffer.
This is (a summary of) my existing code:
//Add Page Numbers
Word.Document docWord;
Word.AutoTextEntries docAutotextEntries;
Word.AutoTextEntry docAutotextEntry;
Word.Section wordSection;
docWord = WordApp.ActiveDocument;
docAutotextEntries = WordApp.NormalTemplate.AutoTextEntries;
object indexitem = 26; //page x of y
docAutotextEntry = docAutotextEntries.get_Item(ref indexitem);
object dirstart = Word.WdCollapseDirection.wdCollapseEnd;
object richtext = true;
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.InsertAfter("\r");
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Collapse(ref dirstart);
docAutotextEntry.Insert(wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range, ref richtext);
I've also tried using the range.fields.add method, instead of the above, and the same thing happens.
Any ideas would be greatfully received! Thanks.