共用方式為


Application.DocumentOpen 事件 (Word)

會在開啟文件時發生。

語法

表情文件開啟 (文件作為文件**)

一個代表在類別模組中宣告事件的「Application」物件的變數。

參數

名稱 必要/選用 資料類型 描述
Doc 必要 Document 正在開啟的文件。

註解

欲了解更多關於在應用程式物件中使用事件的資訊,請參見使用事件與應用程式物件。

範例

本範例會詢問使用者是否要開啟的文件時儲存所有其他開啟的文件。 此程式碼必須置於類別模組中,且類別的實例必須正確初始化,才能讓此範例運作;請參閱 「使用事件搭配應用程式物件」來了解如何達成此目標。

Public WithEvents appWord as Word.Application 
 
Private Sub appWord_DocumentOpen(ByVal Doc As Document) 
 Dim intResponse As Integer 
 Dim strName As String 
 Dim docLoop As Document 
 
 intResponse = MsgBox("Save all other documents?", vbYesNo) 
 
 If intResponse = vbYes Then 
 strName = ActiveDocument.Name 
 For Each docLoop In Documents 
 With docLoop 
 If .Name <> strName Then 
 .Save 
 End If 
 End With 
 Next docLoop 
 End If 
End Sub

另請參閱

Application 物件

支援和意見反應

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