View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
neetha neetha is offline
external usenet poster
 
Posts: 1
Default Calling same event for all the toolbox controls in the sheet

How can i call the same event for all the toolbox controls in an excel
sheet.
I have got a code from this site to call the same event if the controls
are of same type.
This is the code for calling the keydown event for textboxes. But is
there a way I can use the same code for all the controls in the
sheet(option button, textbox etc).

'in the workbook open

Public C As Collection
Set C = New Collection

For Each Obj In Sheet1.OLEObjects

If (TypeOf Obj.Object Is MSForms.TextBox) Then
C.Add New Class1
With C(C.Count)
Set .TB = Obj.Object
Set .Object = Obj
.Index = C.Count

End With
End If

Next Obj

' in the class1 module

Public WithEvents TB As MSForms.TextBox
Dim I , TBCount As Integer

Private Sub TB_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
If KeyCode < 9 Then Exit Sub
TBCount = ThisWorkbook.C.Count
If Shift Then
If Index = 1 Then I = TBCount Else I = Index - 1
Else
If Index = TBCount Then I = 1 Else I = Index + 1
End If
ActiveWindow.RangeSelection.Select
ThisWorkbook.C(I).Object.Activate
End Sub