0
votes

I have a table with 2 columns. The first has a checkbox, the second contains the text. The checkbox highlights the cell

Sub CB1_Click()
If CB1 = True Then
For Each itable In ActiveDocument.Tables
itable.Cell(1, 2).Range.Select
Next
End If
End Sub

The problem is if I check the third row down, the first row loses its selection and does not remain highlighted:

Sub CB3_Click()
If CB3 = True Then
For Each itable In ActiveDocument.Tables
itable.Cell(3, 2).Range.Select
Next
End If
End Sub

How can I change the code so after CB1 is clicked, the text in the 2nd coluimn of the first row remains selected when I click on CB3. It is the same effect as holding down the CTRL key and then clicking into the cell I want to copy. I just want to use the checkbox for the same purpose.

1
Unfortunately, there is no support for working with non-contiguous selections or ranges via the Word object model. Selecting multiple ranges can only be done by the user. - Dirk Vollmar
P.S.: The limitations are documented here - Dirk Vollmar

1 Answers

0
votes

Do you need them "highlighted" or just want the background color to change that is easy

    itable.Cell(1, 2).Shading.BackgroundPatternColor =wdColorAqua

you can later search for the different background colors to do things with the data

But I would suggest not using a table and moving to using a user form which can be set to do just about anything with clicks

you need to set up the form so that one checkbox does not turn off others

I use many such forms for data input in my EHR

if you don't want to change the entire cell just use highlight

    Selection.Range.HighlightColorIndex = wdTeal