Launching a macro by double-clicking on active cell

A

aca

How can I make my macro to be executed when the user double-clicks on
the active cell of Excel?
Thanks for any help.
aca
 
P

Piranha

aca,

When you go into the VBA Edit window for your worksheet module.
Click on the left slot and choose "Worksheet"
Then click on the right slot and you wil have some selections.
Choose this one:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel
As Boolean)

This help?
 
G

Guest

On the sheet tab you want to react to the double click, right click the tab
and select veiw code. This will take you to the VBE. Paste this code in and
you are off and running...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Cancel = True
MsgBox Target.Address
End Sub
 
P

Patrick Molloy

use the sheet's 'before doubleclick event'
to get to the sheet's code page, right click while pointing at the sheet's
tab, then select 'View Code'

add this:

Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If Target.Value = "GO" Then
Cancel = True
Call MyProcedure
End If
End Sub
Sub MyProcedure()
MsgBox "done"
End Sub

If the cell contains the word GO then the procedure is called.

This alternative runs a procedure whose name is in the cell that is
double-clicked.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If Target.Value <> "" Then
On Error Resume Next
Run Target.Value
Cancel = Err.Number = 0
End If
End Sub

In this case the procedure must be public and in a standard module. There's
an error trap, so if a sub exists it runs, if not, the double click event
continues.

HTH
 
A

aca

Thank you for your quick response.
I'm going to try it, though I'am a very, very beginner and I may not be
able to do steps that are obvious for you, programmers.
But that is no less merit on your part.
God bless you.
aca
 
A

aca

Thank you for your quick response.
I'm going to try it, though I'am a very, very beginner and I may not b
able to do steps that are obvious for you, programmers.
But that is no less merit on your part.
God bless you.
aca


Jim said:
On the sheet tab you want to react to the double click, right click th
tab
and select veiw code. This will take you to the VBE. Paste this code i
and
you are off and running...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cance
As
Boolean)
Cancel = True
MsgBox Target.Address
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top