The Object Hierarchy

     

As you've seen, your computer's objects are arranged in a hierarchy with the most general object (the computer as a whole) at the top. Lower levels progress through more specific objects (such as the system unit, the motherboard, and the processor).

Each Office application's objects are arranged in a hierarchy also. The most general object ”the Application object ”refers to the program itself. In Word, for example, the Application object contains more than 30 objects, including the Documents object (the collection of all open documents, each one being a Document object), the Options object (the settings available in the Options dialog box), and the RecentFiles object (the names of the files that have been used most recently).

Many of these objects have objects beneath them in the hierarchy. A Document object, for example, contains objects that represent the document's characters , words, sentences, paragraphs, bookmarks, and much more. Similarly, a Paragraph object contains objects for the paragraph format and the tab stops.

To specify an object in the hierarchy, you usually start with the uppermost object and add the lower objects, separated by periods. For example, here's one way you could specify the first word in the second paragraph in a document named Memo.doc :

 Application.Documents("Memo.doc").Paragraphs(2).Range.Words(1) 

As you'll see, there are ways to shorten such long-winded "hierarchical paths."



Absolute Beginner's Guide to VBA
Absolute Beginners Guide to VBA
ISBN: 0789730766
EAN: 2147483647
Year: 2003
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net