Document オブジェクトでのイベントの使用 (Publisher)

Document オブジェクトは、BeforeCloseOpenRedoShapesAddedShapesRemovedUndoWizardAfterChange の 7 つのイベントをサポートしています。 ThisDocument という名前のクラス モジュールで、これらのイベントに応答するプロシージャを記述します。

イベント プロシージャを作成するには、次の手順に従います。

  1. Under your publication project in the Project Explorer window, double-click ThisDocument. フォルダー ビューでは、ThisDocumentMicrosoft Publisher Objects フォルダーにあります。

  2. Select Document from the Object drop-down list box.

  3. [ プロシージャ] ボックスでイベントを選択します。 空のサブルーチンがクラス モジュールに追加されます。

  4. イベントが発生したときに実行する Visual Basic 命令を追加します。

次の使用例は、文書が開かれるときにメッセージを表示する Open イベント プロシージャを示しています。

Private Sub Document_Open() 
    MsgBox "This publication is copyrighted." 
End Sub

The following example shows a BeforeClose event procedure that prompts the user for a yes or no response before closing a document.

Private Sub Document_BeforeClose(Cancel As Boolean) 
    Dim intResponse As Integer 
 
    intResponse = MsgBox("Do you really want to close " _ 
        & "the document?", vbYesNo) 
 
    If intResponse = vbNo Then Cancel = True 
End Sub

注:

Application オブジェクトのイベント プロシージャの作成については、「 Application オブジェクト でのイベントの使用」を参照してください。

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。