I am attempting to have the mouse pointer move at the center of the selected cell when navigating from cell to cell with the Arrow keys
In Excel 2010 the following solution works perfectly
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
SetCursorPos _
ActiveWindow.ActivePane.PointsToScreenPixelsX(Target.Left + (Target.Width / 2)), _
ActiveWindow.ActivePane.PointsToScreenPixelsY(Target.Top + (Target.Height / 2))
End Sub
However in Excel 2003 ActiveWindow.ActivePane
does not have the PointsToScreenPixelsX
and PointsToScreenPixelsY
methods. So I tried to find another solution such as the one below. The X Axis works fine but the Y Axis does not.
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
SetCursorPos _
ActiveWindow.Application.ActiveWindow.PointsToScreenPixelsX((Target.Left + (Target.Width / 2)) / 0.75), _
ActiveWindow.Application.ActiveWindow.PointsToScreenPixelsY((Target.Top + (Target.Height / 2)) / 0.75)
End Sub
I wish this to work regardless of resolution etc. Any ideas?