Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Word Solutions
 How to: Retrieve Start and End Char...
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Microsoft Visual Studio Tools for the Microsoft Office system (version 3.0)
How to: Retrieve Start and End Characters in Ranges

Updated: November 2007

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Document-level projects

  • Application-level projects

Microsoft Office version

  • Word 2003

  • Word 2007

For more information, see Features Available by Application and Project Type.

This example demonstrates how you can retrieve the character positions of the start and end positions of a range.

To retrieve start and end characters of a range in a document-level customization

  • Get the values of the Start()()() and End()()() properties of the Range object. The following code example gets the start and end position of the second sentence in the document. To use this code example, run it from the ThisDocument class in your project.

    Visual Basic
    Dim rng As Word.Range = Me.Sentences(2)
    
    Dim startPosition As String = rng.Start.ToString()
    Dim endPosition As String = rng.End.ToString()
    
    MessageBox.Show("Start: " & startPosition & " End: " & endPosition, "Range Information")
    
    
    C#
    Word.Range rng = this.Sentences[2];
    
    string startPosition = rng.Start.ToString();
    string endPosition = rng.End.ToString();
    
    MessageBox.Show("Start: " + startPosition + " End: " + endPosition, "Range Information");
    
    

To retrieve start and end characters of a range by using an application-level add-in

  • Get the values of the Start()()() and End()()() properties of the Range object. The following code example gets the start and end position of the second sentence in the active document. To use this code example, run it from the ThisAddIn class in your project.

    Visual Basic
    Dim rng As Word.Range = Me.Application.ActiveDocument.Sentences(2)
    
    Dim startPosition As String = rng.Start.ToString()
    Dim endPosition As String = rng.End.ToString()
    
    MessageBox.Show("Start: " & startPosition & " End: " & endPosition, "Range Information")
    
    
    C#
    Word.Range rng = this.Application.ActiveDocument.Sentences[2];
    
    string startPosition = rng.Start.ToString();
    string endPosition = rng.End.ToString();
    
    MessageBox.Show("Start: " + startPosition + " End: " + endPosition, "Range Information");
    
    
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker