+ Reply to Thread
Results 1 to 8 of 8

Launching a macro by double-clicking on active cell

  1. #1
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Launching a macro by double-clicking on active cell

    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

  2. #2
    Forum Contributor
    Join Date
    02-26-2005
    Posts
    175
    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
    Quote Originally Posted by 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
    Last edited by Piranha; 08-04-2005 at 03:19 PM.

  3. #3
    Jim Thomlinson
    Guest

    RE: Launching a macro by double-clicking on active cell

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


  4. #4
    Patrick Molloy
    Guest

    Re: Launching a macro by double-clicking on active cell

    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
    >




  5. #5
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Thanks to Patrick Molloy, from 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

    Quote Originally Posted by 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" <[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
    >

  6. #6
    Forum Contributor
    Join Date
    08-04-2005
    Location
    Madrid, Spain
    MS-Off Ver
    2010
    Posts
    241

    Thanks to Jim Thomlinson

    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


    Quote Originally Posted by 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
    >
    >

  7. #7
    Registered User
    Join Date
    01-10-2013
    Location
    Albany, NY
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Launching a macro by double-clicking on active cell

    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.

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Launching a macro by double-clicking on active cell

    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]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1