Application.DocumentOpen 事件 (Word)

會在開啟文件時發生。

語法

運算式。DocumentOpen (Doc As Document**)

運算式 變數,代表以類別模組中的事件宣告的 'Application' 物件。

參數

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

註解

如需搭配 Application 物件使用事件的詳細資訊,請參閱 搭配 Application 物件使用事件。

範例

本範例會詢問使用者是否要開啟的文件時儲存所有其他開啟的文件。 此程式碼必須放置在類別模組中,並且必須正確初始化該類別的執行個體才能看到此範例工作;如需如何完成這項操作的指示,請參閱搭配 Application 物件使用事件。

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 支援與意見反應。