Remove Dynamically Added Controls from Userform

前端 未结 6 519
野的像风
野的像风 2021-01-02 01:13

I have an Excel userform with dynamically added checkboxes.

I add the checkboxes with code that looks like this:

Set chkBox = Me.Controls.Add(\"Forms         


        
6条回答
  •  攒了一身酷
    2021-01-02 01:49

    Adding a check for the control seemed to fix this. Not entirely sure why, but it works.

       Dim j As Integer
    'Remove all dynamically updated checkboxes
    For Each cont In Me.Controls
        If TypeName(cont) = "CheckBox" Then
            For j = 1 To NumControls
                If cont.Name = "Checkbox" & j Then
                    Me.Controls.Remove cont.Name
                    Exit For
                End If
            Next j
        End If
    Next cont
    

提交回复
热议问题