|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
How to: Reference Documents in the Documents Collection
Some code examples in this topic use the this or Me keyword or the
You can refer to aobject as a member of the collection by using the name of the document or its index value in the collection.
Referring to a document by its name is usually the better choice if you want to work with a specific document. You rarely refer to a document by using its index value in the Documents collection because this value can change for a given document as other documents are opened and closed.
To reference a document by its name
Set an object variable to point to the named document, SampleDoc.doc.
If you want to access data binding or the additional events added to a, you must declare the variable as the type Microsoft.Office.Tools.Word.Document.
If you want to refer to the active document (the document that has focus), you can use the
Me reference when you need to refer to the document that has the focus.
To reference the active document
Retrieve the name of the active document using ActiveDocument.