mardi 31 mai 2016

Parcourir la liste des control sur un formulaire (CheckBox, TextBox, ComboBox...)


A placer dans un UserForm. Cela fonctionne sur n'importe quel type de control.

Dim objControl As Control

'variante 1
For Each objControl In Me.Controls
  If TypeOf objControl Is MSForms.TextBox Then 'modifier ici le type si nécessaire
    MsgBox objControl.Name
  End If
Next

'variante 2
For Each objControl In Me.Controls
  If TypeName(objControl) = "TextBox" Then 'modifier ici le type si nécessaire
    MsgBox objControl.Name
  End If
Next