Microsoft Office Tutorials and References
In Depth Information
Selecting text in a Word 2007 document
// Using InsertBefore method inserts text
this.Application.ActiveDocument.Content.InsertBefore("Text @ the
Start - ");
// Using InsertAfter method inserts text
this.Application.ActiveDocument.Content.InsertAfter(" - Text @
the End");
The same insert text operation can be performed using the Selection object. The
following is sample code for this:
// Using Selection Object inserting text after the text
this.Application.Selection.InsertAfter(" - Text @ the End");
// Using Selection Object inserting text before the text
this.Application.Selection.InsertBefore("Text @ the Start - ");
Selecting text in a Word 2007 document
Selecting text content in Word 2007 document can be achieved using the Sentences
collection. By using the Range object, you can set the range of the text content to be
selected in Word 2007. The Select() method is used to select text in Word 2007; this
method is available in the Range object.
// Initializing the Range object
Word.Range PacktRangeSelect;
// Check the sentence count
if (this.Sentences.Count >= 1)
{
// Set the start and ent point has object
object pktStartFrom = this.Sentences[2].Start;
object pktStopHere = this.Sentences[5].End;
// Assign the selection range
PacktRangeSelect = this.Range(ref pktStartFrom,
ref pktStopHere);
// Select the sentence using Select() method
PacktRangeSelect.Select();
}
else
{
return;
}
 
Search JabSto ::




Custom Search