vendredi 30 juillet 2021

Checkbox FOR loop array in VBA

I have a word document with 100+ checkboxes. It is an ActiveX object. The Checkbox1.Caption is the GroupName. If a Checkbox is checked (Checkbox1.Value = True) then I want to display that GroupName in a Message Box to allow the user to easily copy groups as text that are checked without having to scan the whole document. My code works fine, except that I have Set each CheckBox to allow it to be used in array for FOR loop. I'd like to use a for Loop to pass all Checkbox objects into an array which I can then use in the code

'Set CBox(1) = CheckBox1
'Set CBox(2) = CheckBox2
'Set CBox(3) = CheckBox3

 Dim iCount As Integer
 Dim CheckBox As String

 For iCount = 1 To 3
 CBox(iCount) = "CheckBox" & iCount
 Next iCount

 Dim Grp(1 To 50) As String
 Dim GrpText(1 To 5) As String

 Dim i As Integer
 Dim j As Integer
 Dim k As Integer

 For i = 1 To 3
 If CBox(i).Value = True Then Grp(i) = CBox(i).Caption & ";" Else Grp(i) = ""
 Next i

 For j = 1 To 5
    For k = ((j - 1) * 10 + 1) To ((j - 1) * 10 + 10)
      GrpText(j) = Grp(k) & GrpText(j)
    Next k
 Next j
 InputBox "Copy The Below Text", "Groups", GrpText(1) & GrpText(2) & GrpText(3) & GrpText(4) &       GrpText(5)



Aucun commentaire:

Enregistrer un commentaire