none
"This command is not available" when adding field to table cell RRS feed

  • Question

  • I'm trying to add a field inside a table cell, but it throws a COMException that says "This command is not available." I found a similar question already but that person's issue was that they were using a table's range, not a cell's range.

    public void addTableRow_Click(IRibbonControl control)
    {
        ThisDocument doc = Globals.ThisDocument;
        Table table = Globals.ThisDocument.Application.Selection.Tables[1];
        Row row = table.Rows.Add();
        row.Cells.Merge();
        Range r = row.Cells[1].Range;
        try
        {
            Field f = doc.Fields.Add(r, WdFieldType.wdFieldDocProperty, "mydocpropertyname", false); // exception thrown here
        }
        catch (Exception e)
        {}
    }

    A document property with the name "mydocpropertyname" does exist. I create it upon startup. I have checked that the name is not typo'd.

    Why is this failing?

    Thursday, September 24, 2015 2:46 PM

Answers