오빠두엑셀 `2026 무료 챌린지` 오픈! 완주하고 수료증 받아가세요! 5년 연속 IT분야 베스트셀러! 「 진짜쓰는 실무엑셀 」로 2026년 공부 끝내기 엑셀이 막히셨나요? Q&A 게시판에서 바로 해결하세요.
메뉴
미해결 엑셀2021윈도우10

선택셀로 마우스 위치 이동시키는코드

나야
10월 19일 조회 2,310
커서는 A2셀에 있고 마우스 위치는 B5의 위치에 있는데 마우스의 위치를 A2셀로 이동시키는 코드가 있을까요?

커서위치는 행열번호로 구할수있는데 선택셀의 마우스 좌표를 못구하겠네요

행열이 숨겨져 있을수 있습니다.

페이지설정 100으로 하고 아래처럼했을때 잘됐는데  스크롤로 내렸을 경우에는 오류가 있네요

 

Public Declare PtrSafe Function GetCursorPos Lib "user32" (MouseCursor As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Private Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Const MOUSEEVENTF_LEFTDOWN = 2
Const MOUSEEVENTF_LEFTUP = 4

Sub dhGetCurorPos()
Dim MouseCursor As POINTAPI
GetCursorPos MouseCursor
Debug.Print MouseCursor.x & "," & MouseCursor.y
End Sub
Sub M_Click(x, y)

Dim i As Long
Call SetCursorPos(x, y)
Application.Wait Now + TimeValue("00:00:01")

Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

End Sub
Sub 위에서아래로()
Dim 높이, 행 As Long
행 = ActiveCell.Row
For i = 1 To 행
If Cells(i, 1).EntireRow.Hidden = False Then
높이 = 높이 + Cells(i, 1).RowHeight
End If
Next
'Call M_Click(160, Round((높이 - Cells(행, 1).RowHeight / 2) * (574 / 440) + 271, 0))

SetCursorPos 160, Round((높이 - Cells(행, 1).RowHeight / 2) * (574 / 440) + 271, 0) '- 13 '271-메뉴위치 574마우스좌표 440행높이
'mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
' mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
' mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
' mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub

챗gpt 도움받아가며 만들었네요

Public Declare PtrSafe Function GetCursorPos Lib "user32" (MouseCursor As POINTAPI) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Private Declare PtrSafe Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Declare PtrSafe Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Const MOUSEEVENTF_LEFTDOWN = 2
Const MOUSEEVENTF_LEFTUP = 4

Sub dhGetCurorPos()
Dim MouseCursor As POINTAPI
GetCursorPos MouseCursor
Debug.Print MouseCursor.x & "," & MouseCursor.y
End Sub
Sub M_Click(x, y)

Dim i As Long
Call SetCursorPos(x, y)
Application.Wait Now + TimeValue("00:00:01")

Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

End Sub
Sub 위에서아래로()
Dim 높이, 행 As Long
Dim FirstVisibleRow As Long
On Error Resume Next
FirstVisibleRow = ActiveWindow.VisibleRange.Cells(1, 1).Row
On Error GoTo 0
If FirstVisibleRow > 0 Then
첫번째 = FirstVisibleRow
' MsgBox "화면에 보이는 첫 번째 행의 번호: " & FirstVisibleRow
Else
' MsgBox "화면에 보이는 데이터가 없습니다."
End If
행 = ActiveCell.Row
For i = 첫번째 To 행
If Cells(i, 1).EntireRow.Hidden = False Then
높이 = 높이 + Cells(i, 1).RowHeight
End If
Next
'Call M_Click(160, Round((높이 - Cells(행, 1).RowHeight / 2) * (574 / 440) + 271, 0))

SetCursorPos 160, Round((높이 - Cells(행, 1).RowHeight / 2) * (574 / 440) + 271, 0) '- 13 '271-메뉴위치 574마우스좌표 440행높이
'mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
' mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
' mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
' mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End Sub
KakaoTalk_20231019_102502502.jpg

댓글 0

질문답변 게시판의 최근 글

스크랩 완료