Share via


Document.ActivateEvent Event (2007 System)

Occurs when the document becomes the active window.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

Syntax

'Declaration
Public Event ActivateEvent As WindowEventHandler
'Usage
Dim instance As Document 
Dim handler As WindowEventHandler 

AddHandler instance.ActivateEvent, handler
public event WindowEventHandler ActivateEvent
public:
 event WindowEventHandler^ ActivateEvent {
    void add (WindowEventHandler^ value);
    void remove (WindowEventHandler^ value);
}
JScript does not support events.

Remarks

The ActivateEvent event occurs only when you move the focus within an application. Moving the focus to or from an object in another application does not trigger the event.

Examples

The following code snippet displays a message when the document is activated.

This version is for a document-level customization.

Private Sub DocumentActivateEvent()
    AddHandler Me.ActivateEvent, AddressOf ThisDocument_ActivateEvent
End Sub 

Private Sub ThisDocument_ActivateEvent(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Word.WindowEventArgs)
    MessageBox.Show("The document has been activated")
End Sub
private void DocumentActivateEvent()
{
    this.ActivateEvent += new Microsoft.Office.Tools.Word.WindowEventHandler(ThisDocument_ActivateEvent);
}

void ThisDocument_ActivateEvent(object sender, Microsoft.Office.Tools.Word.WindowEventArgs e)
{
    MessageBox.Show("The document has been activated");
}

This version is for an application-level add-in.

Private Sub DocumentActivateEvent()
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    AddHandler vstoDoc.ActivateEvent, AddressOf ThisDocument_ActivateEvent
End Sub 

Private Sub ThisDocument_ActivateEvent(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.WindowEventArgs)
    System.Windows.Forms.MessageBox.Show("The document has been activated")
End Sub
private void DocumentActivateEvent()
{
    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.ActivateEvent += new Microsoft.Office.Tools.Word.WindowEventHandler(ThisDocument_ActivateEvent);
}

void ThisDocument_ActivateEvent(object sender, Microsoft.Office.Tools.Word.WindowEventArgs e)
{
    System.Windows.Forms.MessageBox.Show("The document has been activated");
}

.NET Framework Security

See Also

Reference

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace

Change History

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.