C# Word Automation : How to add a Shape textbox
Though I took quite a lot of time to figure it out; when I did – it actually seemed pretty simple !
Shape wrdTextBox = wrdDocument.Shapes.AddTextbox( Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 0, 2, 500, 30, ref objRange);
WHERE
wrdDocument
- Active word document object of type : Microsoft.Office.Interop.Word.Document
objRange
- Range object in wrdDocument where I want this text box to be inserted of type : Microsoft.Office.Interop.Word.Range
In order to assign text and style to this text box:
wrdTextBox.TextFrame.TextRange.Text = "I am sitting right inside a textbox in word"; wrdTextBox.TextFrame.TextRange.set_Style(ref my_style);
Important information
You need to add a COM reference to your favorite word object library which should in turn add
- Microsoft.Office.Core
- VBIDE
- Word
If you do not see these added, make sure you have PIAs for office version installed on your machine.
Get Office 2007 PIAs here
Get Office 2003 PIAs here
Related Posts
- C# Word Automation: Inserting Images
- C# Word Automation: Inserting images with text wrapping around
- C# Word Automation: Solve “The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)”
Advertisement
Categories: .NET
