text with style (Word 9.0 interop)
I'm using the Word 9.0 interop (out of necessity!) to generate a Word catalog from a normal document with bookmarks that I use for a template. I'm running this against Word 2000.
I can write out my data just fine, but it doesn't seem to copy the style information... so I'm trying to assign that manually. Here's the relevent code (limited to just the "PRE" section of the template, because it's all the same):
try
{
alTemplateRow = (ArrayList)htTemplate[sField];
Word.Style sPRE = (Word.Style)alTemplateRow[1];
Object osPre = sPRE;
ioWord.Selection.TypeText((string)alTemplateRow[3]);
// next line blows up
ioWord.Selection.set_Style(ref osPre);
}
catch (Exception e)
{
MessageBox.Show("Exception! e: " + e);
}
The style is coming from the template, from this code:
oRange = oDocTemplate.Bookmarks.Item(ref oIndex).Range;
Word.Style sFIELD = (Word.Style)ioWord.Selection.get_Style();
alBookmarkLine.Add(sFIELD);
...
htTemplate.Add(oBookmarkName, alBookmarkLine);
set_Style throws the exception:
Exception! e: System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))
at Word.Selection.set_Style(Object& prop)
any ideas?

