mercredi 25 février 2015

Read in MS WordVBA the status of a checkbox in Word table cells

I have a set of identical word files containing a set of yes/no questions organized in a table with simple checkboxes (from the developer tab / Content Controls) included in columns 3 and 5, correspondent to the Yes or No answer. Basically each row of the table contains the same number of columns, but that is not always the case. Dependent on the word file, the Yes and No checkboxes are either checked and unchecked. I want to write a VBA macro in MS Word in order to process this set of Word files, and so count the number of yes and no's for each of the questions. The word files are already available and their format cannot be changed any more. As a first step in this task I am trying to recognize when a table cell contains a checkbox, and then if it is the case read the status of the checkbox: checked or unchecked. So far I came to the following code to identify the checkboxes but I still did not manage to get it working. VBA complains with a compilation error: "Object Required", at line "set nitem.....". Any ideas what am I doing wrong?



Dim tbl As Table
Dim cl As Cell
Dim nitem As Integer

''All tables
For Each tbl In ActiveDocument.Tables
For Each cl In tbl.Rows(1).Cells
If Not cl.Range.ContentControls Is Nothing Then
Set nitem = c1.Range.ContentControls.Count
MsgBox ("Nr of Items" & nitem)
If c1.Range.ContentControls.Item(1).Type = wdContentControlCheckBox Then
''Select ...
cl.Column.Select
.........
End If
End If
Next
Next




Aucun commentaire:

Enregistrer un commentaire