Based on your previous post, you don't want to do that. What you want is a class that handles the combobox events. For example:
Class called CComboHandler
Option Explicit
Public WithEvents Combo As MSForms.ComboBox
Private Sub Combo_Change()
' put whatever code you like in here
MsgBox "You changed combo " & Combo.Name
End Sub
Then in sheet module of sheet with comboboxes on:
Option Explicit
' collection to hold the combobox handlers
Dim colHandlers As Collection
Public Sub HookCombos()
Dim objHandler As CComboHandler
Dim objOLE As OLEObject
' initialise the collection that holds the handlers
Set colHandlers = New Collection
For Each objOLE In Me.OLEObjects
' hook the combos
If TypeName(objOLE.Object) = "ComboBox" Then
' create new handler instance
Set objHandler = New CComboHandler
' assign the combobox to it
Set objHandler.Combo = objOLE.Object
' now add to collection, so the handler doesn't go out of scope
colHandlers.Add objHandler
End If
Next objOLE
End Sub
Private Sub Worksheet_Activate()
HookCombos
End Sub
and you can also call the HookCombos sub from the Workbook_Open event:
Option Explicit
Private Sub Workbook_Open()
Sheet1.HookCombos
End Sub
Demo file attached.
Bookmarks