Condividi tramite


DTE2.ActiveDocument Property

Definition

Gets the active document.

public:
 property EnvDTE::Document ^ ActiveDocument { EnvDTE::Document ^ get(); };
public:
 property EnvDTE::Document ^ ActiveDocument { EnvDTE::Document ^ get(); };
[System.Runtime.InteropServices.DispId(221)]
public EnvDTE.Document ActiveDocument { [System.Runtime.InteropServices.DispId(221)] get; }
[<System.Runtime.InteropServices.DispId(221)>]
[<get: System.Runtime.InteropServices.DispId(221)>]
member this.ActiveDocument : EnvDTE.Document
Public ReadOnly Property ActiveDocument As Document

Property Value

A Document object.

Implements

Attributes

Examples

Sub ActiveDocumentExample()  
  Dim objTextDoc As TextDocument  
  Dim objEP As EditPoint  

  ' Create a new text document.  
  Call DTE2.ItemOperations.NewFile("General\Text File")  
  'Get a handle to the new document.  
  Set objTextDoc = DTE2.ActiveDocument.Object("TextDocument")  
  Set objEP = objTextDoc.StartPoint.CreateEditPoint  
  'Create an EditPoint and add some text.  
  objEP.Insert "A test sentence."  
End Sub  

Sub DocumentExample()  
  Dim doc As Document  
  Dim desc As String  

  Set doc = DTE2.ActiveDocument  
  desc = "You are editing a "  
  If (doc.ReadOnly) Then  
    desc = desc & "read-only"  
  Else  
    desc = desc & "writable"  
  End If  
  desc = desc & " document called " & doc.Name & " located at " & doc.Path  
  MsgBox desc  
End Sub  

Remarks

An active document is one that has focus. To make another document active, set the focus on its window.

You can set the caption only on Tool windows. If you attempt to set the caption on other window types, such as Document windows, you get the error, "Unspecified error."

Applies to