+ Reply to Thread
Results 1 to 8 of 8

Command to tie mouse wheel click to a macro same way as Worksheet_BeforeRightClick

Hybrid View

luv2glyd Command to tie mouse wheel... 03-06-2013, 05:22 PM
JosephP Re: Command to tie mouse... 03-06-2013, 05:41 PM
luv2glyd Re: Command to tie mouse... 03-06-2013, 05:59 PM
JosephP Re: Command to tie mouse... 03-06-2013, 06:44 PM
luv2glyd Re: Command to tie mouse... 03-06-2013, 07:09 PM
JosephP Re: Command to tie mouse... 03-07-2013, 03:36 AM
JosephP Re: Command to tie mouse... 03-07-2013, 05:14 AM
luv2glyd Re: Command to tie mouse... 03-07-2013, 03:30 PM
  1. #1
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Command to tie mouse wheel click to a macro same way as Worksheet_BeforeRightClick

    I'd like to have a click on the scroll wheel trigger a macro execution similar to this:

    Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    MsgBox "You clicked right mouse button."
    End Sub
    Is there a way to do this? If tying code execution to wheel click is not possible, I'd be willing to tie it to scrolling the wheel.

    Thanks
    Last edited by luv2glyd; 03-06-2013 at 05:37 PM.
    You either quit or become really good at it. There are no other choices.

  2. #2
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Command to tie mouse wheel click to a macro same way as Worksheet_BeforeRightClick

    neither event is exposed in the excel model so you would have to subclass the excel window and intercept the mouse messages. not trivial code and not something I would typically recommend in vba
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  3. #3
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: Command to tie mouse wheel click to a macro same way as Worksheet_BeforeRightClick

    Ok, thanks. Alternatively is there a way to tie keyboard keys to mouse buttons. So for example, left mouse button tied to up arrow, right mouse button tied to down arrow and the wheel click tied to right arrow keys? I'm writing a game in excel and it is much easier if the mouse is used vs. the keyboard to trigger macros.

    Thanks

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Command to tie mouse wheel click to a macro same way as Worksheet_BeforeRightClick

    no-that would require the same coding principle. why are you using excel for this?

  5. #5
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: Command to tie mouse wheel click to a macro same way as Worksheet_BeforeRightClick

    The whole game/program is in excel and uses a lot of charts. Also, I don't realy know how to write code for anything else besides excel vba. Are there some other ways to do what I am after besides vba?

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Command to tie mouse wheel click to a macro same way as Worksheet_BeforeRightClick

    I'd suggest you stick with the keyboard or have a modeless userform with buttons you can click

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Command to tie mouse wheel click to a macro same way as Worksheet_BeforeRightClick

    in fact depending on your layout you might be able to use an activex control on a worksheet to trap the mouse events-you could overlay it on the worksheet and make it transparent. depends if you need to be able to use the worksheet or if it's just for display

  8. #8
    Valued Forum Contributor luv2glyd's Avatar
    Join Date
    07-13-2008
    Location
    Seattle, WA, US
    MS-Off Ver
    Excel 2010
    Posts
    679

    Re: Command to tie mouse wheel click to a macro same way as Worksheet_BeforeRightClick

    I've though of that, though I would not be able to use the middle button of the mouse (the wheel) click to trigger execution of code. Or would I??

    The only other solution which I found would be temporary remapping the mouse buttons to keyboard buttons that I rarely use, like the F-keys and then making that key a shortcut to a macro, like this:

    Sub AssignShortcuts()
        Application.OnKey "{F12}", "Macro1"
    End Sub
    I used X-Mouse Button Control from download.com. It comes with a bunch of other junk software, so for anyone that's reading this in the future, make sure to delete it all right away. Still, let me know if there's a way to use the wheel click to trigger code with an activex control. That would be simpler if it's possible.
    Last edited by luv2glyd; 03-07-2013 at 03:34 PM.

+ 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