Word Automation and Basic text formatting option

Hi,

when you start working with word programmatically, many a times you will have to add some text in the word document with formatting. Word automation gives you easy way top format the text that you are writing in the Word document programmatically.

To make the same impact as would an enter button in the word document we can use the following code.

oWord.Selection.TypeParagraph();

Basically this will enter a new paragraph in the word document. But you are in a bullet mode than this will take you to next line and also add the next bullet in the sequence.

Some of the common word formatting functionality can easily be performed with the help of word automation.

oWord.Selection.Font.Bold = 1;

oWord.Selection.Font.Color = Word.WdColor.wdColorAqua;

oWord.Selection.Font.Italic = 1;

oWord.Selection.Font.Underline = Word.WdUnderline.wdUnderlineDashHeavy;


This will change the formatting in the selected text in the active word document in the application. You can also find many more formatting options in the font class. Remember once you apply the formatting and till you remove the formatting, the formatting will continue till we remove the formatting. To remove the formatting we need to use the following code.

oWord.Selection.ClearFormatting();

To add text in the word document we can use the following code.

oWord.ActiveWindow.Selection.TypeText("www.vikramLakhotia.com");


Vikram


Share this post   Email it

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Copyright © 2006 - 2010 Vikram Lakhotia