Visio (的 Window.Document 屬性)

取得與 物件相關聯的 Document 物件。 唯讀。

語法

運算式文檔

表達 代表 Window 物件的變數。

傳回值

文件

註解

固定樣板視窗的 Document 屬性會傳回目前在視窗頂端之樣板的 Document 物件。 如果另一個樣板取代了頂端位置的第一個樣板,則第一個樣板的文件會關閉,使該文件的參考變得無效。 若要達到最佳結果,請假設文件不是持續參考固定樣板。

如果 Window 物件顯示未開啟任何檔,則不會傳回任何檔,而且不會引發任何例外狀況。 您的方案在擷取 Window 物件的 Document 屬性之後應該檢查所傳回的 Nothing

範例

下列的 Microsoft Visual Basic for Applications (VBA) 巨集會示範如何使用不同物件的 Document 屬性來擷取這些物件的相關資料,並執行下列步驟:

  • 它會將 Document 物件新增到 Documents 集合,並設定數個 Document 物件的屬性。

  • 它會取得使用中的視窗和頁面、在頁面上繪製矩形,並在 Document 物件上放置主圖形以提供各種可用物件。

  • 它會使用 Document 屬性來取得與這其他每個物件相關的 Document 物件。

 
Public Sub Document_Example() 
 
 Dim vsoDocument As Visio.Document 
 Dim vsoTempDocument As Visio.Document 
 Dim vsoPage As Visio.Page 
 Dim vsoShape As Visio.Shape 
 Dim vsoWindow As Visio.Window 
 Dim vsoMaster As Visio.Master 
 
 'Add a document to the Documents collection. 
 Set vsoDocument = Documents.Add("") 
 
 'Set the title of the document. 
 vsoDocument.Title = "My Document" 
 
 'Get the active window and active page. 
 Set vsoWindow = ActiveWindow 
 Set vsoPage = ActivePage 
 
 'Draw a rectangle on the page. 
 Set vsoShape = vsoPage.DrawRectangle(2, 2, 5, 5) 
 
 'Add a master. 
 Set vsoMaster = vsoDocument.Masters.Add 
 
 'Get the Document object associated with various other objects.'Get the Document object associated with the Window object. 
 Set vsoTempDocument = vsoWindow.Document 
 
 'Get the Title property of the Document object to verify that this is the same document we added earlier. 
 Debug.Print vsoTempDocument.Title 
 
 'Get the Document object associated with the Page object. 
 Set vsoTempDocument = vsoPage.Document 
 Debug.Print vsoTempDocument.Title 
 
 'Get the Document object associated with the Shape object. 
 Set vsoTempDocument = vsoShape.Document 
 Debug.Print vsoTempDocument.Title 
 
 'Get the Document object associated with the Master object. 
 Set vsoTempDocument = vsoMaster.Document 
 Debug.Print vsoTempDocument.Title 
 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應