1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

マウスポインタ移動VBA

Last updated at Posted at 2024-04-16
Option Explicit

Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As LongPtr, ByVal y As LongPtr) As Long


Sub MovePointer()

Dim i As Long, j As Long
Dim x As Double, y As Double
Dim rng As Range

Application.Cursor = xlNorthwestArrow

For i = 3 To 10 Step 2
    For j = 1 To 40 Step 2
        Set rng = Cells(j, i)
        x = ActiveWindow.PointsToScreenPixelsX(rng.Left * 96 / 72) + rng.Width / 2
        y = ActiveWindow.PointsToScreenPixelsY(rng.Top * 96 / 72) + rng.Height / 2

        Debug.Print rng.Address(0, 0) & ":x=" & x & ",y=" & y

        SetCursorPos x, y
        Application.Wait Now() + TimeValue("00:00:01")
        Set rng = Nothing
    Next j
Next i

Application.Cursor = xlDefault

End Sub
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?