Microsoft Office Tutorials and References
In Depth Information
Working with key objects
Selection object
The Selection object either represents the currently-selected area in our document,
or it represents the insertion point, if nothing in the document is currently selected. If
the requirement is to work with the active selection, you have to use the Selection
object. This shares many properties and methods with the Range object.
// A few ways to access the Selection object
// Access the Selection object through ActiveDocument object
this.Application.ActiveDocument.Sections;
// Access the Selection object through ActiveWindow object
this.Application.ActiveWindow.Selection;
Tables collection object
The Tables collection is a collection of Table objects that represent the tables in a
selection, range, or document. It is accessed via the construct Tables ( Index ), where
Index is the index number, which returns a single Table object. The index number
represents the position of the table in the selection, range, or document.
// Way to access Table Object
this.Application.ActiveDocument.Tables[int IndexValue];
Working with key objects
Now that you've seen a simple Hello world application and some basic methods,
let's work out some of the underlying concepts of the Word 2007 object model, using
some key objects in Word 2007. It is not feasible to entirely describe the Word object
model in this section, but I'll try to make you comfortable with the most important
objects in the Word object model and the most frequently used methods, properties,
and events for these objects.
By using Word 2007, VSTO 3.0, and Visual Studio 2008, you can now apply
sophisticated concepts including looping through collections, editing texts,
working with range objects, prompting for information, and much more.
Inserting text in Word 2007 document
Inserting text in Word 2007 document can be achieved using Range objects and
Selection objects. There are methods available for inserting text inside the Word
2007 document. InsertAfter method inserts text at the end of the active range
or selection, whereas InsertBefore inserts text at the start of the active range or
selection. The example code for both these methods is as follows:
 
Search JabSto ::




Custom Search