0
0

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 3 years have passed since last update.

【ExcelVBA】マウスポインタの移動

Last updated at Posted at 2021-03-05

マウスポインタの移動のみ。
クリックはしていない。


Option Explicit

Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) 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
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?