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 enumerated value that is passed to method. If you call get_Information on a Range with an enumerated type that is not applicable, get_Information will return 1 as a return value.

This is an example of getting information associated with the Range.


public void sampleCode()
 {
 Object missing = System.Reflection.Missing.Value;
 Word.Range r = Globals.ThisAddIn.Application.ActiveDocument.Range(ref missing, ref missing);

r.Text = "This\nis\na\ntest.";

object startIndex = 0;
 object endIndex = 9;

Word.Range r2 = Globals.ThisAddIn.Application.ActiveDocument.Range(ref startIndex, ref endIndex);
 r2.InsertAfter("\n");

for (int i = 1; i < 27; i++)
 {
 GetInfo(r2, (Word.WdInformation)i);
 }
 }

private void GetInfo(Word.Range r, Word.WdInformation info)
 {
 string result = String.Format(
 "Range.Information({0}) returns {1}.\n",
 info.ToString(), r.get_Information(info));
 r.InsertAfter(result);
 }

You can learn output (return value) of the code yourself.

<< BACK

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s