# Microsoft Office Application Help - Excel Help forum > Excel Programming / VBA / Macros >  >  Launching a macro by double-clicking on active cell

## 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

----------


## 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?
Dave




> 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

----------


## Jim Thomlinson

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
--
HTH...

Jim Thomlinson


"aca" wrote:

>
> 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
>
>
> --
> aca
> ------------------------------------------------------------------------
> aca's Profile: http://www.excelforum.com/member.php...o&userid=25933
> View this thread: http://www.excelforum.com/showthread...hreadid=393051
>
>

----------


## 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



"aca" <aca.1t97fh_1123182417.0641@excelforum-nospam.com> wrote in message
news:aca.1t97fh_1123182417.0641@excelforum-nospam.com...
>
> 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
>
>
> --
> aca
> ------------------------------------------------------------------------
> aca's Profile:
> http://www.excelforum.com/member.php...o&userid=25933
> View this thread: http://www.excelforum.com/showthread...hreadid=393051
>

----------


## 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





> 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)
> ...

----------


## 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






> 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
> ...

----------


## emu5088

Sorry to bump an old thread, but this is pretty much how I want to start a macro. I'm a very beginner here, as well. I used your advice, and I used this code just to start a macro. I'm getting a type mismatch error whenever I click on a cell that didn't have the text it's looking for initially. (instead of "do" I have "click to generate report"). So I click on a cell that says "click to generate report" and the macro runs. Also, if I change a cell that had "click to generate report" to a word or number, and double click it, the macro doesn't run. (I want this). But if I double click on any other cell I get "Run-time error '13': type mismatch." I'm guessing this is because it's looking for a string but the cells are in number format.. Help please.

-emu5088




```
Please Login or Register  to view this content.
```

----------


## arlu1201

This is a 7.5 yr old thread and you are not likely to get any responses.  Its better you start your own thread.

----------

