none
cell selection on mouse up event RRS feed

  • Question

  • Hello all,

    I was wondering if it is possible to select a cell using x and y values from the mouse up event.  Any insight is appreciated.

    Monday, August 22, 2011 4:41 PM

Answers

  • Hi Derek,

    As far as I know, you can use pInvoke to get the current cursor postion, here is the code snippet for you to reference:

    Dim MyPointAPI As POINTAPI
    Private Type POINTAPI
      X As Long
      Y As Long
    End Type

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

    Public Sub Timer1_Timer()
      l = GetCursorPos(MyPointAPI)
     Debug.Print CStr(MyPointAPI.X) & ", " & CStr(MyPointAPI.Y)
    End Sub

    Because Excel does not expose the mouse up event for us, then you can call the Timer1_Timer() function in this way:


    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Timer1_Timer
    End Sub

    Hope this can help you and just feel free to follow up after you have tried. Wish you a nice day.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 23, 2011 7:32 AM

All replies

  • Hi Derek,

    As far as I know, you can use pInvoke to get the current cursor postion, here is the code snippet for you to reference:

    Dim MyPointAPI As POINTAPI
    Private Type POINTAPI
      X As Long
      Y As Long
    End Type

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

    Public Sub Timer1_Timer()
      l = GetCursorPos(MyPointAPI)
     Debug.Print CStr(MyPointAPI.X) & ", " & CStr(MyPointAPI.Y)
    End Sub

    Because Excel does not expose the mouse up event for us, then you can call the Timer1_Timer() function in this way:


    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Timer1_Timer
    End Sub

    Hope this can help you and just feel free to follow up after you have tried. Wish you a nice day.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 23, 2011 7:32 AM
  • When you release the mouse over cells you have just selected a cell or a range of cells (assuming the mouse was pressed down over cells). What are you actually trying to do.

    Peter Thornton

    Tuesday, August 23, 2011 2:36 PM
    Moderator