I want to write some text to an existing word textbox using C#. Actually nothing happens and I don't know why. Maybe someone can help me?
My method:
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oWordDoc = new Microsoft.Office.Interop.Word.Document();
void SearchTextBox(Microsoft.Office.Interop.Word.Document oDoc, string name, string newContent)
{
foreach (Microsoft.Office.Interop.Word.Shape shape in oDoc.Shapes)
{
if (shape.Name == name)
{
shape.TextFrame.TextRange.Text = newContent;
return;
}
}
}
Call:
SearchTextBox(oWordDoc, "tbTest", "Please write some Text");
Here the solution: