I have a number of ActiveX checkboxes in a Word document that are called 'CheckBox1', 'CheckBox2' etc.
I have a private sub for a when a button is clicked it looks at these checkboxes and if certain boxes are ticked it runs a macro. If I access the checkboxes individually using me.CheckBox1, me.CheckBox2 etc the code works fine, but I want to be able to run a loop that runs through them like me.checkBox[variable] but I can't get it to work. Any ideas? Thanks!
Follow-up: I have tried the code that Tim kindly put below however I am still unable to use the checkboxes in a meaningful way. I have put in:
Sub checkCheckBox() Dim obj, i As Long Dim boxName As String For i = 1 To 10 Set obj = GetControlByName(ThisDocument, "CheckBox" & i) boxName = obj.Name If ThisDocument.boxName.Value = True Then .... ' do something End If Next i End Sub
If I use ThisDocument.CheckBox1.Value and hard code it that way it works, but it is not liking the variable.
https://stackoverflow.com/questions/66885481/loop-activex-checkboxes-with-a-variable March 31, 2021 at 05:56PM
没有评论:
发表评论