0

Objective

I have a table in Word with 2 columns. The first has a drop down Content Control.

I would like to populate the second column with text, the value of which depends on the option selected.

Question

Is it possible to get the cell reference that contains the clicked content control? I plan to use that to target the next column with the content. I'm thinking of something like this:

    Dim oCell As Cell
    oCel = 'some way to get cell reference containing the ContentControl here
    Dim curCellRow, curCellCol, targetCellRow, targetCellCol As Integer
    curCellRow = oCell.Row
    curCellCol = oCell.Column
    targetCellRow = curCellRow
    targetCellCol = curCellCol + 1

    Dim NewCellContents As String
    NewCellContents = "Sample Content for this cell"

    ActiveDocument.Tables(1).Cell(targetCellRow, targetCellCol).Range.Text = NewCellContents
braX
  • 11,506
  • 5
  • 20
  • 33
Martin Hansen Lennox
  • 2,837
  • 2
  • 23
  • 64

2 Answers2

0

I worked it out - here's how I did it:

    Dim RowNum As Long, ColNum As Long
    If Selection.Information(wdWithInTable) Then
    RowNum = Selection.Cells(1).RowIndex
    ColNum = Selection.Cells(1).ColumnIndex
    MsgBox "Row = " & RowNum & vbCr & _
    "Column = " & ColNum
    Else
    MsgBox "Not in table"
    End If
Martin Hansen Lennox
  • 2,837
  • 2
  • 23
  • 64
0

I had a similar need and used the following code in the ContentControlOnExit event in ThisDocument.

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim TableNum As Long, RowNum As Long, ColNum As Long
If ContentControl.Range.Information(wdWithInTable) Then
    TableNum = Me.Range(0, ContentControl.Range.End).Tables.Count
    RowNum = ContentControl.Range.Information(wdStartOfRangeRowNumber)
    ColNum = ContentControl.Range.Information(wdStartOfRangeColumnNumber)
End If
' more code
End Sub


JC_RMB
  • 99
  • 9