Application.ActiveDocument property (Word)
Returns a Document object that represents the active document (the document with the focus). If there are no documents open, an error occurs. Read-only.
Note
The document in the active Protected View window cannot be accessed using this property. Instead, use the Document property of the ActiveProtectedViewWindow object.
Syntax
expression.ActiveDocument
expression A variable that represents an Application object.
Example
This example displays the name of the active document, or if there are no documents open, it displays a message.
If Application.Documents.Count >= 1 Then
MsgBox ActiveDocument.Name
Else
MsgBox "No documents are open"
End If
This example collapses the selection to an insertion point and then creates a range for the next five characters in the selection.
Dim rngTemp As Range
Selection.Collapse Direction:=wdCollapseStart
Set rngTemp = ActiveDocument.Range(Start:=Selection.Start, _
End:=Selection.Start + 5)
This example inserts texts at the beginning of the active document and then prints the document.
Dim rngTemp As Range
Set rngTemp = ActiveDocument.Range(Start:=0, End:=0)
With rngTemp
.InsertBefore "Company Report"
.Font.Name = "Arial"
.Font.Size = 24
.InsertParagraphAfter
End With
ActiveDocument.PrintOut
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기