The Document Object

 < Free Open Study > 

The Documents Collection

The Documents collection contains all of the Document objects in the IDE. Each object represents an open document. You can reference all of the open documents by looping through the Documents collection. Executing the code sample in Listing 5-1 in an add-in closes all open documents that have been previously saved.


When DTE is the parent object in sample code, and I am discussing code within an add-in, I will always use the application object and substitute the variable name oVB for DTE.You will remember from Chapter 3 that I used oVB as ashort name for the application object. DTE will be used as the real object when I discuss code examples in Chapter 8.

Listing 5-1: Closing Saved Documents

start example
     ' Close all saved documents.     Dim i As Integer     With oVB         Try            For i = 1 To .Documents.Count               If .Documents.Item(i).Saved Then                  .Documents.Item(i).Close()               End If            Next I         Catch         ' Ignore any error we raise attempting to close     End Try End With 
end example

 < Free Open Study > 

Writing Add-Ins for Visual Studio  .NET
Writing Add-Ins for Visual Studio .NET
ISBN: 1590590260
EAN: 2147483647
Year: 2002
Pages: 172
Authors: Les Smith © 2008-2017.
If you may any questions please contact us: