【发布时间】:2022-01-11 16:54:54
【问题描述】:
我正在尝试识别范围的表索引;或更具体地说: 我有一个带有一些表格的 Word 文档,每个表格都包含复选框类型的 ContentControls。我正在循环 ContentControls,如果类型是 CheckBox,那么我想操作表格中的文本,但要做到这一点,我需要知道表格索引。 我可以确定 CheckBox 是否实际上在一个表中(两种方法之一),我可以识别行号和列号,但我还没有弄清楚如何建立表号。
Dim docActive As Document
Dim ContCtrl As ContentControl
Dim TableNo As Integer
Dim UpperLeftText As String
Set docActive = ActiveDocument
For Each ContCtrl In docActive.ContentControls
If ContCtrl.Type = wdContentControlCheckBox Then
If ContCtrl.Range.Information(wdWithInTable)
MsgBox ("RowNumber: " & ContCtrl.Range.Information(wdEndOfRangeRowNumber))
TableNo = ContCtrl.Range.Information(wdTableNumber)) ' This doesn't work, I know, and this is the line for which I need help
MsgBox ("TableRef: " & TableNo)
UpperLeftText = docActive.Tables(TableNo).Rows(1).Cells(1).Range.Text ' Contents of upper left cell assigned to variable UpperLeftText
End If
End If
Next
有什么想法吗?
是的,我可以算出表格的数量,然后循环遍历这些表格,这将是一个已知的数字,但这并不是很优雅...
【问题讨论】: