InvisibleApp ActiveDocument 屬性 (Visio)InvisibleApp.ActiveDocument property (Visio)

會傳回使用中**** 物件, 這是顯示在使用中視窗中的檔。Returns the active Document object, which is the document shown in the active window. 唯讀。Read-only.

語法Syntax

運算式ActiveDocumentexpression.ActiveDocument

_運算式_代表**InvisibleApp** 物件的變數。expression A variable that represents an InvisibleApp object.

傳回值Return value

DocumentDocument

註解Remarks

當沒有任何文件開啟時,將不會有任何使用中的文件,且 ActiveDocument 屬性會傳回 Nothing 值,且不會觸發例外狀況。When no documents are open, there is no active document and the ActiveDocument property returns the value Nothing and does not raise an exception.

如果您的程式碼在 Visio 檔的 Microsoft Visual Basic 專案中, 則ActiveDocument屬性通常不一定會傳回**ThisDocument** 物件的參考 (即每個 Microsoft Visio 的 Visual Basic 專案中的類別模組)進.If your code is in the Microsoft Visual Basic project of a Visio document, the ActiveDocument property often, but not necessarily, returns a reference to the ThisDocument object, a class module in the Visual Basic project of every Microsoft Visio document. 如果 ThisDocument 物件顯示在使用中視窗內,則 ActiveDocument 物件和 ThisDocument 物件會參考相同的文件。If the ThisDocument object is shown in the active window, the ActiveDocument object and the ThisDocument object refer to the same document. 從專案內的程式碼參考 ThisDocument 物件時,它會傳回此專案之 Document 物件的參考。When the ThisDocument object is referenced from code in a project, it returns a reference to the project's Document object.

要使用 ActiveDocument 物件或 ThisDocument 物件是依程式碼的用途而定。Whether you use the ActiveDocument object or the ThisDocument object depends on the purpose of your code.

您可以將 ActiveDocument 屬性所傳回的結果與 Nothing 值進行比較,判斷文件是否在使用中。You can compare the result returned by the ActiveDocument property with the value Nothing to determine if a document is active. 如果**Documents** 屬性的值大於零、至少有一個檔處於開啟和使用中狀態。If the value of the Documents.Count property is greater than zero, at least one document is open and active.

範例Example

下列 Microsoft Visual Basic for Applications (VBA) 巨集示範兩種取得使用中文件 (如果存在的話) 的安全方式。The following Microsoft Visual Basic for Applications (VBA) macro shows two safe ways to get an active document (if one exists). 在兩種情況中,此巨集都會在 [立即] 視窗內顯示使用中文件的名稱。In each case, it prints the name of the active document in the Immediate window. 此程式碼會取得使用中檔, 但不需從 Visio 全域物件進行限定, 這會自動提供給屬於 Visio 檔之 VBA 專案一部分的 VBA 程式碼。The code gets the active document without qualification from the Visio global object, which is automatically available to VBA code that is part of the VBA project of a Visio document.

 
Public Sub ActiveDocument_Example() 
 
 Dim vsoDocument As Document 
 
 'First method 
 If Documents.Count > 0 Then 
 Set vsoDocument = ActiveDocument 
 Debug.Print vsoDocument.Name 
 Else 
 Debug.Print "No active document." 
 End If 
 
 'Second method 
 If Not(ActiveDocument Is Nothing) Then 
 Set vsoDocument = ActiveDocument 
 Debug.Print vsoDocument.Name 
 Else 
 Debug.Print "No active document." 
 End If 
 
End Sub

支援和意見反應Support and feedback

有關於 Office VBA 或這份文件的問題或意見反應嗎?Have questions or feedback about Office VBA or this documentation? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.