2
범위를 선택할 때 고유 한 값의 수를 반환하고 Excel의 상태 표시 줄에 표시하기 위해 작은 매크로를 만들었습니다. 이것은 문서 수준에서 잘 작동합니다. 그러나 응용 프로그램 수준에서 실행하려고하면 SelectionChange
이벤트가 시작되지 않습니다. 다음은 내가 가지고있는 것입니다.응용 프로그램 수준에서 SelectionChange 이벤트가 작동하지 않는 이유는 무엇입니까?
클래스 모듈 'ExcelEventCapture'
Option Explicit
Public WithEvents ExcelApp As Application
Private Sub ExcelApp_SelectionChange(ByVal Target As Range)
If TypeName(Target) = "Range" Then
Application.StatusBar = "Unique Count: " & CountUnique(Target)
End If
End Sub
Private Function CountUnique(rng As Range) As Long
Dim dict As Dictionary
Dim cell As Range
Set dict = New Dictionary
For Each cell In rng.Cells
If cell.Value2 <> 0 Then
If Not dict.Exists(cell.Value) Then
dict.Add cell.Value, 0
End If
End If
Next
CountUnique = dict.Count
End Function
내가 무엇을 놓치고
Option Explicit
Dim myobject As New ExcelEventCapture
Sub Workbook_Open()
Set myobject.ExcelApp = Application
End Sub
을에서 ThisWorkbook? 감사합니다