Mac said:
that is a good start.
how do we intercept the click event? we tried both the Document and
Application objects, but neither seem to fire the click event to fire on
those...
BTW: we are using Mac Office 2004
I see. The click event works with UserForms. This code works for a
userform that has a button on it named MyButton. It's slightly modified
from the VBA Help examples.
When you run the form and click somewhere else besides the button, the
form changes size. If you click on the button, the caption on the button
changes. Frustratingly, the accelerator key doesn't work. I put the
following code on the Userform module:
Option Explicit
Public tag
Private Sub MyButton_Click()
If MyButton.Caption = "OK" Then 'Check caption, then change it.
MyButton.Caption = "Clicked"
MyButton.Accelerator = "C" 'Set Accelerator key to
COMMAND + C
Else
MyButton.Caption = "OK"
MyButton.Accelerator = "O" 'Set Accelerator key to
COMMAND + O
End If
End Sub
' Activate event for UserForm1
Private Sub UserForm_Activate()
UserForm1.Caption = "Click me to make me taller!"
Let tag = UserForm1.Height ' Save the initial height.
MsgBox tag
End Sub
' Click event for UserForm1
Private Sub UserForm_Click()
Dim NewHeight As Single
NewHeight = Height
' If the form is small, make it tall.
If NewHeight = Val(tag) Then
Height = Val(tag) * 2
Else
' If the form is tall, make it small.
Height = Val(tag)
End If
End Sub
' Resize event for UserForm1
Private Sub UserForm_Resize()
UserForm1.Caption = "New Height: " & Height & " " & "Click to
resize me!"
End Sub
If you poke around the Help system in the visual basic editor you'll
find more events that work with UserForms
Help topic: UserForm Object, UserForms Collection - Events
AddControl Event
BeforeDragOver Event
BeforeDropOrPaste Event
Click Event
DblClick Event
Error Event
KeyDown, KeyUp Events
KeyPress Event
Layout Event
MouseDown, MouseUp Events
MouseMove Event
RemoveControl Event
Scroll Event
Zoom Event
Activate, Deactivate Events
Terminate Event (Visual Basic for Applications)
So what I want to know is if you are using userforms or whether your are
trying to detect events as they occur as a user is working in a Word
document rather than a userform? The events that work for Word documents
rather than userforms are the ones you mentioned earlier:
Document.Close
Document.New
Document.Open
Application.DocumentChange
Application.Quit
I'm not sure exactly what you're trying to do. Excel and PowerPoint have
their own object models and offer different event handling options.
Excel has an event handler that can be initiated by changes made on a
worksheet. See the SheetChange Event in Excel's VBA Help for an example.
Maybe something I've said here will be of assistance.
-Jim