Export (0) Print
Expand All
Expand Minimize
0 out of 4 rated this helpful - Rate this topic

ActiveDocument Property (DTE Object)

Visual Studio .NET 2003

Returns the active document.

[Visual Basic .NET]
Public ReadOnly Property ActiveDocument() As Document
[Visual Basic 6]
Property Get ActiveDocument() As Document
HRESULT __stdcall get_ActiveDocument(
   /* [out, retval] */ Document** retVal
public Document ActiveDocument {get;}
[JScript .NET]
public function get ActiveDocument() : Document

Return Value

Returns a Document object.


An active document is one that has the 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."


Sub ActiveDocumentExample()
  Dim objTextDoc As TextDocument
  Dim objEP As EditPoint
  'Create a new text document.
  Call DTE.ItemOperations.NewFile("General\Text File")
  'Get a handle to the new document.
  Set objTextDoc = DTE.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 = DTE.ActiveDocument
  desc = "You are editing a "
  If (doc.ReadOnly) Then
    desc = desc & "read-only"
    desc = desc & "writable"
  End If
  desc = desc & " document called " & doc.Name & " located at " & doc.Path
  MsgBox desc
End Sub

See Also

Document Object

Applies To: DTE Object

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.