Workbook.EventCode

Use this property to return or set the event code of a document.

Syntax Parameters Return value
- - String

SVB Example

Adding and running document-level events in a workbook

Option Base 1
Option Explicit
Sub Main
    Dim wb As WorkBook
    Set wb = WorkBooks.New("New Workbook")
    'insert a function into the workbook that will
    'display a message box whenever it 
    'is activated
    wb.EventCode = _
        "Private Sub Document_Activate()" & vbCrLf & _
        "MsgBox(EventSource.Name & "" now activated"",vbExclamation)" & _
        vbCrLf & "End Sub"
    wb.Visible = True
    wb.RunEvent()
End Sub