问题
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
回答1:
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
来源:https://stackoverflow.com/questions/25314641/word-vba-how-to-locate-table-cell-containing-content-control