Application-Level Events Example

Application-level events can be used to customize the behavior of all STATISTICA documents of a certain type (such as all spreadsheets, all workbooks, or all reports). Follow these step-by-step instructions to customize all spreadsheets by changing the meaning of double-clicks on spreadsheet cells. In more technical terms, this example will create event procedures for events in all of the STATISTICA Spreadsheets.

1. Ribbon bar. Select the Tools tab. Click Macro and from the Application Events submenu, select View Code to display the Document Events dialog box, in which you can associate certain events with all spreadsheets.
Classic menus. From the Tools menu, select Macro - Application Events - View Code to display the Document Events dialog box, in which you can associate certain events with all spreadsheets.

2. In the Document Events dialog box, in the Object box select Document, and in the Proc box select SpreadsheetBeforeDoubleClick. After you do this, the following code is displayed:

Private Sub Document_SpreadsheetBeforeDoubleClick _
(
ByVal Spreadsheet As Object, _
ByVal
Flags As Long, _
ByVal
VarNo As Long, _
ByVal
CaseNo As Long, _
Cancel
As Boolean)

End Sub

This code is a placeholder for the event code.

3. Change the event procedure code to the following:

Private Sub Document_SpreadsheetBeforeDoubleClick _
(
ByVal Spreadsheet As Object, _
ByVal
Flags As Long, _
ByVal
VarNo As Long, _
ByVal
CaseNo As Long, _
Cancel
As Boolean)

MsgBox "Double-clicks not allowed here"

Cancel = True

End Sub

4. Run the event handler by selecting the Debug tab and clicking Run (ribbon bar) or by selecting Run macro from the Run menu (classic menus). Hence, you have specified (via the code added in the previous step) that when you double-click on any spreadsheet cell, a message box will be displayed that says "Double-clicks not allowed here."

5. Ribbon bar. Select the Home tab. In the Tools group, click Macro and from the ApplicationEvents submenu, select Autorun. Classic menus. From the Tools menu, select Macro - Application Events - Autorun.

6. Close STATISTICA, and then open it again.

7. Now, open any spreadsheet, and whenever you double-click on a cell, the "Double-clicks not allowed here" message box will be displayed.

To "disconnect" this event handler, clear the Autorun command.

See Application-Level Events for a listing of application events. See also Macro Event Behavior.