Option Explicit
Private pSortButtons As Collection
Private Sub Workbook_Open()
Dim SortEvent As c_BeforeSort
Set pSortButtons = New Collection
'sort (from Data Menu)
Set SortEvent = New c_BeforeSort
Set SortEvent.cbbSort = Application.CommandBars.FindControl _
(Type:=msoControlButton, ID:=928)
pSortButtons.Add SortEvent
'sort ascending
Set SortEvent = New c_BeforeSort
Set SortEvent.cbbSort = Application.CommandBars.FindControl _
(Type:=msoControlButton, ID:=210)
pSortButtons.Add SortEvent
'sort descending
Set SortEvent = New c_BeforeSort
Set SortEvent.cbbSort = Application.CommandBars.FindControl _
(Type:=msoControlButton, ID:=211)
pSortButtons.Add SortEvent
End Sub
Option Explicit
Public WithEvents cbbSort As CommandBarButton
Private Sub cbbSort_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
If ActiveWorkbook Is ThisWorkbook Then
'let's just select the currentregion.
If TypeOf Selection Is Range Then Selection.CurrentRegion.Select
End If
End Su
If Not Application.Intersect(Target, Range("A1:I100") Then
If Application.Intersect(Target, Range("A1:I100")).Columns.Count > 5 Then
Range("A1:I100").Select
End If
End If
Option Explicit
Public WithEvents cbbSort As CommandBarButton
Private Sub cbbSort_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
Dim rngActiveCell As Range
If ActiveWorkbook Is ThisWorkbook Then
If TypeOf Selection Is Range Then
Set rngActiveCell = ActiveCell
Selection.CurrentRegion.Select
Intersect(rngActiveCell.EntireColumn, Selection.Cells(1).EntireRow).Activate
End If
End If
End Sub