Alerter Message Display Component
This page introduces the Alerter message display component
Frequently, a VBA application needs to display messages to the user, especially if
you are the user and you are debugging some code. Using native Excel and VBA objects,
you have three methods to display information:
- MsgBox message boxes
- Debug.Print statements
- Application.StatusBar messages
Each of these has disadvantages. For example, a MsgBox requires that you click
on it to continue running code. Having to click off a number of message boxes quickly
becomes tiresome. Debug statement show up only in the VBA editor, so you have
to switch between Excel and VBA to see the messages. StatusBar messages are not
very obvious and one message disappears as the next one is displayed.
The Alerter component overcomes these limitations. It is an ActiveX DLL, usable
in any Office program, 97 or later, that displays a modeless form on which messages
can be displayed. Since it is modeless, it can remain visible while your code executes.
Messages remain in the display as new messages are added, scrolling upwards. The
Alerter screen is shown below:
Download the zip file to some directory, unzip the file, and run AlerterSetup.exe. This will install Alerter to the folder of your
choice and register the component with Windows. You can
download the Alerter Setup program
here. You can download an
example workbook here.
Once you have installed Alerter, you need to set a reference to the DLL file from
your VBA project. In the VBA editor, go to the Tools menu, choose References
and scroll down to Alerter and check the box, as shown below.
With this reference in place, you can use the Alerter object and its methods.
First, declare a Public variable of the type Alert.Alerter and then set the properties.
For example,
Public Alerter As Alert.Alerter
Sub InitializeAlerter()
If Alerter Is Nothing Then
Set Alerter = New Alert.Alerter
End If
With Alerter
.SetParentWindow -1
.Caption = "Alerts For Testing"
.EnableEVents = True
.FormVisible = True
.MaxListCount = 100
.MaxPriority = 100
.MinPriority = 1
.ShowCounter = True
End With
End Sub
This will initialize the Alerter component. To display a message in the window,
use code like the following:
Alerter.DoAlert AlertText:="This Is Some Test Code", Priority:=10
The Priority parameter is optional. See below for a description of all parameters,
properties and methods.
The following table describes the properties, methods, and events of the
Alerter object.
Property |
Description
|
Caption |
This sets or returns the
caption of the Alerter form. The default is "Alert Messages". Variable
type: String.
|
Count |
This returns the number of
messages in the Alerter list. Read-only. Variable type: Long
|
EnableEvents |
This sets or returns whether
Alerter should raise its events to the containing class. Variable type:
Boolean.
|
FormVisible |
This sets or returns whether
the Alerter window is visible. Variable type: Boolean.
|
HWnd |
This returns the window handle
of the main Alerter window. Read-only. Variable type: Long
|
LastMessage |
This returns the last (most
recent) message in the Alerter window. Read-only. Variable type: String
|
Left |
This returns the left position
of the Alerter window. Read-only. Variable type: Single
|
MaxListCount |
This sets or returns the
maximum number of messages to display. When
MaxListCount is reached, the earliest (top most) messages are
deleted to make room for new messages. The default is 0, indicating no
maximum. Variable type: Long
|
MaxPriority |
This sets or returns the
maximum priority of messages that will be displayed in the list. If a
message is sent with a Priority greater than
MaxPriority, it will not be displayed. The values you use for the
MinPriority and MaxPriority
are entirely up to you. There is no default. The only restriction is the
both the MinPriority and
MaxPriority must be between 0 and 999999. Variable type: Long
|
MinPriority |
This sets or returns the
minimum priority of messages that will be displayed in the list. If a
message is sent with a Priority less than MinPriority,
it will not be displayed. See MaxPriority.
|
ReturnFocus |
This sets or returns whether
focus should return to the host application. The default value is True.
Variable type: Boolean.
|
ShowCounter |
This sets or returns whether
messages should be displayed with a counter in the list. The default
value is False. Variable type: Boolean
|
ShowPriority |
This sets or returns whether
the Priority should be displayed in the message list. The default value
is False. Variable type: Boolean
|
Top |
This returns the Top position
of the Alerter window. Read-only. Variable type: Single
|
Methods |
|
ClearList |
This clears the message list.
|
DeleteSelectedMessages
|
This deletes messages selected
in the list.
|
DoAlert |
This sends a message to the
Alerter window. This method takes two parameters:
AlertText (required String) is the text of the message to be
displayed; Priority is the priority of the
message (optional Long). If Priority is less than
MinPriority or greater than MaxPriority,
the message will not be displayed. The default priority is -1.
|
ResetCounter |
This resets the message
counter to zero.
|
SetLocation |
This positions the Alerter
window on the screen. This takes two required parameters,
Top and Left, both
Single data types.
|
SetParentWindow |
This sets the parent window of
the Alerter window. If this is numeric and less than or equal to zero,
the Application's main window is used. If numeric and greater than zero,
this is the HWnd of the window to become the parent of the Alerter
window. If this is a string, it should be the Window Class of the new
parent window (e.g., "XLMAIN").
|
Events |
|
AfterAlert |
Raised after an alert has been
posted to the list.
|
AfterClear |
Raised after the message
display has been cleared.
|
AfterPriorityChange |
Raised after either
MinPriority or MaxPriority
has been changed.
|
BeforeAlert |
Raised before an alert is
posted to the list. Set Cancel to True to
cancel the post operation.
|
BeforeClear |
Raised before the message list
is cleared. Set Cancel to True to cancel the
clear operation.
|
BeforeCounterReset |
Raised before the counter is
reset to zero. Set Cancel to True to cancel
the reset operation.
|
BeforeHide |
Raised before the Alerter
window is hidden. Set Cancel to True to cancel
the hide operation.
|
BeforePriorityChange |
Raised before the MinPriority
or MaxPriority is changed. Set Cancel to True
to cancel the change operation.
|
BeforeShow |
Raised before the window is
made visible. Set Cancel to True to Cancel the
show operation.
|
|
|
You can download the Alerter Setup
program here. You can download an
example workbook here.
If you are interested in the VB6 source code,
email me.
This page last updated:
12-July-2007