I have a VSTO project where a click of a button on the ribbon, opens a new Word doc with a specific template, and opens it with a custom task pane. On that pane is a button, which when clicked, i want to add a row to a table which exists in the doc template.
Currently i'm just getting a 'command failed' exception at run time when the button on the task pane is clicked. Here is the whole class. As you can see i've tried two ways to do it, both fail:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using word = Microsoft.Office.Interop.Word;
namespace TestWordAddin2010
{
public partial class NewDescDMtaskPane : UserControl
{
public NewDescDMtaskPane()
{
InitializeComponent();
}
private void addSpare_Click(object sender, EventArgs e)
{
Globals.ThisAddIn.Application.ActiveDocument.Tables[1].Rows.Add(Globals.ThisAddIn.Application.ActiveDocument.Tables[1].Rows[1]); //this doesn't work
//word.Table wordTable = Globals.ThisAddIn.Application.ActiveDocument.Tables[1];
//wordTable.Rows.Add(wordTable.Rows[1]); //neither does this work
}
}
}
Any help appreciated.