Move the mouse cursor in the top left corner of the selected cell.
Hi all.
I would like that the mouse cursor has moved into the top left corner of the selected cell.
I wrote this macro:
Code:
Option Explicit
Private Declare Function SetCursorPos Lib "User32" (ByVal x As Long, ByVal y As Long) As Long
Sub Macro1()
Dim lWinLeft As Long
Dim lWinTop As Long
With ActiveWindow
lWinLeft = .PointsToScreenPixelsX(.Selection.Left)
lWinTop = .PointsToScreenPixelsY(.Selection.Top)
End With
SetCursorPos lWinLeft, lWinTop
End Sub
When I select cell A1, it works properly. But when I select another cell, the mouse cursor is not in the top left corner of the selected cell.
What am I doing wrong?
I apologize for my language. I use a translator.
Artik