我正在嘗試識別范圍的表索引;或者更具體地說:我有一個帶有一些表格的 Word 檔案,每個表格都包含復選框型別的 ContentControl。我正在回圈遍歷 ContentControl,如果型別是 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
有任何想法嗎?
是的,我可以計算出表的數量,然后遍歷這些表,這將是一個已知的數字,但這并不是很優雅......
uj5u.com熱心網友回復:
您不需要通過使用其在檔案的表集合中的索引來訪問內容控制元件所在的表。您可以簡單地使用內容控制元件范圍的 Tables 集合,即
UpperLeftText = ContCtrl.Range.Tables(1).Rows(1).Cells(1).Range.Text
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/375351.html
