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
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,
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
Originally Posted by aca
Last edited by Piranha; 08-04-2005 at 03:19 PM.
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
>
>
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" <[email protected]> wrote in message
news:[email protected]...
>
> 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
>
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
Originally Posted by Patrick Molloy
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
Originally Posted by Jim Thomlinson
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.
This is a 7.5 yr old thread and you are not likely to get any responses. Its better you start your own thread.
If I have helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks