Excel for Mac 2016 right click mousedown mouseup events

Mrock1

New Member
Joined
Oct 7, 2014
Messages
22
I have recently migrated an Excel macro driven time recording application from Winodws to Mac. I have overcome most of the differences in the vba macro language and Mac subtleties, but am left with one small frustration. On my main userform I have a listbox. In the Windows version I was able to create a mousedown event routine that displayed details of the selected item in a "hidden" textbox by updating the text property and making the textbox visible when the right mouse (button 2) is pressed. I then have a corresponding mouseup event that makes the textbox invisible again when the right mouse button is released. This worked great for years in Windows. However in moving to Mac (Yosemite and Office 365 2016) I have found that the mouseup event is triggered immediately after the mousedown even though the button has not been reelased. This is not so for the left mouse button as I have change the routine to respond to button 1 instead of 2 and it works as expected. However this is not ideal as the textbox flashes whenever an item is selected or double clicked and I want to run another routine on a selection change anyway which uses the same textbox for a different purpose.

i have also removed all my code from both the mousedown and mouseup routines, even removed the mousedown routine completely but every time I press and hold the right mouse button on any item in the listbox the mouseup routine triggers immediately after the mousedown event has executed although I have not released the button or moved the mouse. As I said before, the left mouse works as I'd expect it should and it's always worked in Windows.

The simplest code I have tried is as follows. The doevents statement is to allow me to create a break point for debug purposes.
Private sub Listbox1_mousedown(byval button as long, byval shift as long, byval X, byval Y as long)
If button = 2 then
DoEvents
End if
End sub

Private sub Listbox1_mouseup(byval button as long, byval shift as long, byval X, byval Y as long)
If button =2 then
DoEvents
End if
End sub

In the above example the mouseup event triggers immediately after the mousedown routine finishes executing when pressing and holding the right mouse button.
if I use button = 1 and the left mouse button then the mouseup routine does not trigger.

Is this some sort of passive protest against multi-button mice on an Apple ;) ?

Any ideas would be greatly appreciated.
 

Mrock1

New Member
Joined
Oct 7, 2014
Messages
22
Having no responses yet, I assume this is a bug or undocumented feature, so I developed a workaround as follows.

In the userform declarations section defined a variable as follows:
Public MouseJustPressed as Boulean

The create your MouseDown and MouseUp events as follows:

Public ListBox1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 then
MouseJustPressed
{enter what ever code you need your right-mouse-down to do}
End If
End Sub

Public ListBox1_MouseUp((ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 2 then
If MouseJustPressed then
MouseJustPressed = False
Else
{code for mouse release/up}
End If
End If
End Sub

Not ideal, but it works. I hope Microsoft/Apple see the problem and fix it at some stage in the future.
 

Forum statistics

Threads
1,081,513
Messages
5,359,226
Members
400,521
Latest member
smarty1995

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top