Application.DocumentChange 事件 (Word)

會在建立新文件、開啟現有文件,或是當其他文件變成使用中文件時發生。

語法

expression.**DocumentChange' ()

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

註解

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

範例

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

Public WithEvents appWord as Word.Application 
 
Private Sub appWord_DocumentChange() 
 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 支援與意見反應