views:

747

answers:

1

How using VSTO and Word 2003 can I insert text after a table I've created? I have code like

bookmarkDescriptions = (object)"bookmarkDescriptions";
Word.Range rangeDescriptions = aDoc.Bookmarks.get_Item(ref bookmarkDescriptions).Range;

foreach (var item in items)
{
    //Add a paragraph with some text
    Table descTable = aDoc.Tables.Add(oSelection.Range, 1, 2, ref missing, ref missing);
    //Insert some text into the cells
    //Add a another paragraph with some text
}

when I add another paragraph of text it's added within the table but I want it after the table. Since I need to loop over all items and create some text - paragraph - some more text for each of them I don't see how I could make use of a bookmark to get a range after and outside the table.

+1  A: 

I just solved the problem. I am using the following code.

object oLineUnit = (object) Word.WdUnits.wdLine;
object oCountOne = (object) 1;
object oCellUnit = (object) Word.WdUnits.wdCell;

oSelection.MoveRight(ref oCellUnit, ref missing, ref missing);
oSelection.MoveDown(ref oLineUnit, ref oCountTwo, ref missing);

The best way to make sense of the Word object model seems to be to record a macro in Word and to then look at the source code so see what API calls are being made and to then replicate that in your enviroment of choice, hth.

olle