
Selecting a Range by Using an Application-Level Add-In
The following examples show how to select the entire document by using the Select()()() method of a Range object, or by using the Content()()() property of the Document class.
To select the entire document as a range by using the Select method
To select the entire document as a range by using the Content property
You can also use the methods and properties of other objects to define a range.
To select a sentence in the active document
Another way to select a sentence is to manually set the start and end values for the range.
To select a sentence by manually setting the start and end values
Create a range variable.
Check to see if there are at least two sentences in the document, set the Start and End arguments of the range, and then select the range.
|
Dim document As Word.Document = Me.Application.ActiveDocument
If document.Sentences.Count >= 2 Then
Dim startLocation As Object = document.Sentences(2).Start
Dim endLocation As Object = document.Sentences(2).End
' Supply a Start and End value for the Range.
rng = document.Range(Start:=startLocation, End:=endLocation)
' Select the Range
rng.Select()
End If
|
|
Word.Document document = this.Application.ActiveDocument;
if (document.Sentences.Count >= 2)
{
object startLocation = document.Sentences[2].Start;
object endLocation = document.Sentences[2].End;
// Supply a Start and End value for the Range.
rng = document.Range(ref startLocation, ref endLocation);
// Select the Range.
rng.Select();
}
|