I'm creating a MS Word VSTO addin
(Custom Task Pane
) that inserts some text into a Word Document on the click of a button. However, I find that after the button is clicked and the text is inserted into the Document, the cursor doesn't automatically return back to the body of the Document. When I hit the space-bar, it triggers the button click event again, instead of inserting a space into the Document.
This is the c# code from the button click:
public void btnInsert_Click(object sender, EventArgs e)
{
Word.Application objApplication = Globals.ThisAddIn.Application;
Word.Selection objSelection = objApplication.Selection;
Word.Range objRange = objSelection.Range;
objRange.InsertAfter("Sample Text");
objRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
objRange.Select();
}
How do I get the cursor back into the Document once my sample text is inserted?