Home > .NET > C# Word Automation : How to add a Shape textbox

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

Related Posts
Advertisement
Categories: .NET

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.