엑셀 마우스 왼쪽 클릭에 대한 워크 시트 이벤트가 없습니다.
'SelectionChange'에 대한 이벤트가 있으며 API 호출과 결합하여 마우스 왼쪽 버튼이 클릭되었는지 확인할 수 있습니다.
이 코드는 대상 워크 시트의 프로젝트 탐색기 영역에서 시트 개체로 이동해야합니다.
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Key As Integer
If Target.Count > 1 Then Exit Sub
''//If multiple cells selected with left click and drag
''// then take no action
Key = GetKeyState(MOUSEEVENTF_LEFTDOWN)
If Key And 1 Then
If IsNumeric(Target.Value) Then
Target.Value = Target.Value + 1
''//Check to see if cell contains a number, before
''// trying to increment it
Application.EnableEvents = False
Target.Resize(1, 2).Select
Application.EnableEvents = True
''//Resize the selection, so that if the cell is clicked
''// for a second time, the selection change event is fired again
End If
End If
End Sub
이 코드가 작동하지만 사용자가 마우스를 클릭하지 않은 상태에서도 셀 값이 증가 할 수 있습니다.
대신 가능하면 'BeforeDoubleClick'이벤트를 사용하는 것이 좋습니다. 이것은 Excel에 내장되어 있으며 위의 코드보다 더 안정적입니다.
는 셀 값을 증가하기 위해, 사용자는 셀을 두 번 클릭해야합니다.
이 코드는 대상 워크 시트의 프로젝트 탐색기 영역에서 시트 개체로 이동해야합니다.
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If IsNumeric(Target.Value) Then
Target.Value = Target.Value + 1
''//Check to see if cell contains a number, before
''// trying to increment it
Application.EnableEvents = False
Target.Resize(1, 2).Select
Application.EnableEvents = True
''//Resize the selection, so that if the cell is clicked
''// for a second time, the selection change event is fired again
Cancel = True
''//Stop the cell going into edit mode
End If
End Sub
특정 영역 A1 : L29에 대상을 정의 할 수 있습니까? 이 코드는 전체 시트를 선택합니다 –