OnData Property

An OnData event handler runs when data arrives from an application other than Microsoft Excel. You can use the OnData property of either the Worksheet or Application object to associate a procedure with the arrival of data linked to one of these objects through dynamic data exchange (DDE) or OLE.

For example, the following code associates the arrival of stock price data on a worksheet with a procedure that validates each item of information.


Sub TrapData()                        'Set up OnData trapping
    Worksheets("StockAnalysis").OnData = "ValidateData"
End Sub

Sub ValidateData()                    'OnData handler
    For Each Cell in InputRange        'InputRange is a public variable
        CheckData                    'Run my validation procedure
    Next
End Sub

For more information about using DDE and OLE, see Chapter 10, "Communicating with Other Applications."