当使用箭头键从一个单元格导航到另一个单元格时,我试图让鼠标指针移动到所选单元格的中心
在 Excel 2010 中,以下解决方案完美运行
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
但是在 Excel 2003ActiveWindow.ActivePane
中没有PointsToScreenPixelsX
和PointsToScreenPixelsY
方法。所以我试图找到另一种解决方案,例如下面的解决方案。X 轴工作正常,但 Y 轴不行。
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
我希望不管分辨率等如何都能正常工作。有什么想法吗?