![use document properties word 2010 use document properties word 2010](https://i2.wp.com/jahangiri.us/2013/wp-content/uploads/2014/02/word-doc-properties-define1a.png)
The Document object also has a Save method that is available for saving a single document. The following example saves the open documents by applying the Save method. The Documents object has a Save method that saves all the documents in the collection. Sub CloseSalesDoc()Ĭollection objects often have methods and properties that you can use to modify the whole collection of objects. The following example uses a name (specified as a string) to identify a Document object within the Documents collection. The Close method is then applied to the Document object to close the first document in the Documents collection. The index number is used to return the first document in the Documents collection. The following example uses the Documents property to access the Documents collection. For more information, see Returning an Object from a Collection. The index value is usually a number or a name. You use the Documents property of the Application object (the object at the top of the Word object hierarchy) to return the Documents collection.Īfter you access the collection, you can return a single object by using an index value in parentheses (this is similar to how you work with arrays). For example, the Documents collection contains the open Word documents. Most objects are returned by returning a single object from the collection. Using a method causes something to happen to an object, while using a property returns information about the object or causes a quality about the object to change. In most cases, methods are actions and properties are qualities.
![use document properties word 2010 use document properties word 2010](https://i.ytimg.com/vi/VAskwzL7zbI/maxresdefault.jpg)
Sub PrintThreePages()ĪctiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="1-3" The following example prints the first three pages of the active document. Methods often have arguments that qualify how the action is performed.
![use document properties word 2010 use document properties word 2010](http://addbalance.com/word/images/2019DocumentProperties.png)
For example, just as a document can be printed, the Document object has a PrintOut method. What is a method?Ī method is an action that an object can perform. Also, the Object Browser in the Visual Basic Editor displays the read/write status at the bottom of the browser window when the property is selected. The Help topic for each property indicates whether you can set that property (read/write), only read the property (read-only), or only write the property (write-only). The name of that document is assigned to the variable strDocName. The name of that document is assigned to the variable refers to the document in the active window in Word. In this example, ActiveDocument refers to the document in the active window in Word. The following example returns the name of the active document.
![use document properties word 2010 use document properties word 2010](https://i.ytimg.com/vi/SrkRKVhvOek/maxresdefault.jpg)
You can return information about an object by returning the value of one of its properties. The Help topic for a property indicates whether that property can be set (read/write) or can only be read (read-only). The TrackRevisions property is set for that single document. In this example, Documents refers to the collection of open documents, and the name "Sales.doc" identifies a single document in the collection. Sub TrackChanges()ĭocuments("Sales.doc").TrackRevisions = True The following example turns on change tracking in the document named "MyDoc.doc". To set the value of a property, follow the reference to an object with a period, the property name, an equal sign, and the new property value. To change the characteristics of an object, you change the values of its properties. For example, properties of a document include its name, its content, and its save status, and whether change tracking is turned on. What is a property?Ī property is an attribute of an object or an aspect of its behavior. By using properties and methods, you can modify a single object or a whole collection of objects. A collection is an object that contains several other objects, usually of the same type for example, all the bookmark objects in a document are contained in a single collection object. What are objects and collections?Īn object represents an element of Word, such as a document, a paragraph, a bookmark, or a single character. Every element of Microsoft Word-such as documents, tables, paragraphs, bookmarks, and fields-can be represented by an object in Visual Basic. Objects are the fundamental building blocks of Microsoft Visual Basic almost everything that you do in Visual Basic involves modifying objects.