none
Word: How to reference data in table column 'A' after clicking checkbox in table column 'B' RRS feed

  • Question

  • Hi -- using Word 2010.

    I have inserted a table in a word doc. Column A contains text and column B has two checkboxes (with the title of 'Yes' and 'No') that I have inserted from the control group in the developer tab.

    My end goal is to export into some list format (CSV / xls etc.) the contents of column A based on which checkbox is checked in column B. 

    • Iin other words, for all the rows that I checked the checkbox tiled 'No'... I would like the corresponding column A text to be exportable in some fashion. 

    I'm envisioning maybe a button control that would execute a for-each loop thru the table and save the text of column A into an Array.

    Any thoughts would be appreciated.

    Thanks,

    Brad

    Sunday, October 28, 2012 1:00 PM

Answers

  • Something like this:

    Sub ScratchMacro()
    Dim oTbl As Word.Table
    Dim strText As String
    Dim strText2() As String
    Dim i As Long
    Dim oRow As Row
    Set oTbl = ActiveDocument.Tables(1)
    For Each oRow In oTbl.Rows
      If oRow.Range.ContentControls(2).Checked Then
       strText = strText & Left(oRow.Cells(1).Range, Len(oRow.Cells(2).Range) - 2) & "|"
      End If
    Next oRow
    strText = Left(strText, Len(strText) - 1)

    strText2 = Split(strText, "|")
    For i = 0 To UBound(strText2)
      MsgBox strText2(i)
    Next i

     
    End Sub


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Sunday, October 28, 2012 3:45 PM