Navigating a Range

To go to the next element of a particular type without affecting the selection, you can use the GoTo method of the Range object. GoTo doesn’t affect the Range object it is called on but instead returns a new Range object that represents the resulting Range after calling GoTo. The GoTo method takes by reference four optional object parameters. The first parameter, the What parameter, can be passed a member of the WdGoToItem enumeration:

  • wdGoToBookmark
  • wdGoToComment
  • wdGoToEndnote
  • wdGoToEquation
  • wdGoToField
  • wdGoToFootnote
  • wdGoToGrammaticalError
  • wdGoToGraphic
  • wdGoToHeading
  • wdGoToLine
  • wdGoToObject
  • wdGoToPage
  • wdGoToPercent
  • wdGoToProofreadingError
  • wdGoToRevision
  • wdGoToSection
  • wdGoToTable (lebih…)


Identifying a Range

A Range has several properties to help identify it. The get_Information methods takes a parameter of type WdInformation and returns information as an object about the Range depending on the…


Getting a Range

You have several ways to get a range in a word document. VSTO have already considered several document-level collections such as Paragraphs, Sentences, Words and Characters that return Range Object. The most common way to get a Range is to use the Range method on the Documen object. Start and End position represent the start and end position of the Range you want to get within the document. If you omit the Start parameter, it defaults to 0, which is the first position in the document. If you omit the End parameter, it defaults to the last position in the document.

In the nampspace code, type this.

[sourcecode language=”csharp”]
using System;
using System.Collections.Generic;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using System.Reflection;
using System.Windows.Forms;

Get all Range

To get all range in the document, type the code bellow:

[sourcecode language=”csharp”]
public void sampleCode()
object missingValue = System.Reflection.Missing.Value;
Word.Range range = Globals.ThisAddIn.Application.ActiveDocument.Range(ref missingValue, ref missingValue);
MessageBox.Show(String.Format("{0}", range.Text));


MessageBox used for output of the code. Beside it, we know Console.WriteLine. But, MessageBox more efficient. (lebih…)