Montague26
New Member
- Joined
- Dec 6, 2015
- Messages
- 14
I have 20+buttons in a userform, how can I disable all buttons by a automatic sub?
Only buttons
Only buttons
Private Sub UserForm_Initialize()
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "CommandButton" Then
Ctrl.Enabled = False
End If
Next Ctrl
End Sub
Private Sub UserForm_Initialize()
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "CommandButton" _
Or TypeName(Ctrl) = "OptionButton" _
Or TypeName(Ctrl) = "SpinButton" _
Or TypeName(Ctrl) = "ToggleButton" Then
Ctrl.Enabled = False
End If
Next Ctrl
End Sub
You should be able to do your code this way as well...With some help from Andrew. If you want to disable all "buttons" you can use this script:
Code:Private Sub UserForm_Initialize() Dim Ctrl As Control For Each Ctrl In Me.Controls If TypeName(Ctrl) = "CommandButton" _ Or TypeName(Ctrl) = "OptionButton" _ Or TypeName(Ctrl) = "SpinButton" _ Or TypeName(Ctrl) = "ToggleButton" Then Ctrl.Enabled = False End If Next Ctrl End Sub
Private Sub UserForm_Initialize()
Dim Ctrl As Control
For Each Ctrl In Me.Controls
If TypeName(Ctrl) Like "*Button" Then Ctrl.Enabled = False
Next
End Sub
Thanks, I solve it.With some help from Andrew. If you want to disable all "buttons" you can use this script:
Code:Private Sub UserForm_Initialize() Dim Ctrl As Control For Each Ctrl In Me.Controls If TypeName(Ctrl) = "CommandButton" _ Or TypeName(Ctrl) = "OptionButton" _ Or TypeName(Ctrl) = "SpinButton" _ Or TypeName(Ctrl) = "ToggleButton" Then Ctrl.Enabled = False End If Next Ctrl End Sub
Thanks, I solve it.