目的
我在Word中有一个表,有2列。第一列有一个下拉的内容控件。
我想用文本填充第二列,其值取决于所选的选项。
问题:我想用文本填充第二列,其值取决于所选的选项。
是否可以得到包含点击内容控件的单元格引用?我打算用它来锁定下一列的内容。 我想的是这样的。
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
我想出了办法--这是我的方法。
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
我有一个类似的需求,并在ThisDocument的ContentControlOnExit事件中使用了以下代码。
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