tags:

views:

317

answers:

1

In excel 2000, is it possible to bind a vba function to be executed when a cell is clicked with the mouse?

+1  A: 

You can bind to a cell double click.

Open VBA, goto the worksheet you want to wire up the event Select WorkSheet in the dropdown on the top left and BeforeDoubleClick in the top right The check the Target.Address is equal to the address of the cell you care about and call the function you wish.

Something like this:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Target.Address(True, True, xlA1) = "$A$1" Then
        Call MyDemo
    End If
End Sub

Private Sub MyDemo()
    MsgBox "Hello"
End Sub
JDunkerley
double click is good enough for me. great answer. Can the beforeX functions actually cancel the default event processing?
Cheekysoft
I think so. Set Cancel to true I believe - but have never tried!
JDunkerley
hehe. beat me to it by 30 secs. Just found in http://msdn.microsoft.com/en-us/library/aa220840%28office.11%29.aspx. Cancel = True works just great.
Cheekysoft