Carlos Matioli
Carlos Matioli

Reputation: 67

VBa to clear all activex checkboxes in Word document

I'm trying to create a button to clear all the activex check-boxes in a .docm file, but nothing seems to work. I saw many posts in the fórum, but none seems to work. Can anyone help me? Obs.: the original file have at least 30 check boxes and I don't want to type all the check-boxes names. See the code below and the example file attached

Ps.: I tried ThisDocument.Fields; Me.Control and many others.

See attached image as example: ActiveX CheckBox

Private Sub CommandButton1_Click()
Dim Ctl As MSForms.Control

    For Each Ctl In ThisDocument.FormFields
        If Ctl.Name = "CheckBox" Then Ctl.Value = False
    Next Ctl
End Sub

Upvotes: 1

Views: 1043

Answers (1)

Carlos Matioli
Carlos Matioli

Reputation: 67

After many tests, the code below solved my problem:

Private Sub Limpar_Click()
Dim iShp As InlineShape
For Each iShp In ActiveDocument.InlineShapes
  If iShp.OLEFormat.ClassType = "Forms.CheckBox.1" Then
                iShp.OLEFormat.Object.Value = False
            End If
    Next
End Sub

Upvotes: 2

Related Questions