' ' ' VB
Sub ProcessSelectedColumn()
Dim oTbl As Table
Dim oCell As Cell
Dim iRow As Integer
Dim iCol As Integer
Dim oRange As Range
' 检查是否有表格被选中,且只选中了一个表格的有效内容
If Selection.Information(wdWithInTable) Then
On Error Resume Next
Set oTbl = Selection.Tables(1)
On Error GoTo 0
' 如果成功获取到表格对象
If Not oTbl Is Nothing Then
' 这里假设你原本是想处理用户指定列,可通过以下方式让用户选择列(示例,可根据实际需求完善)
iCol = InputBox("请输入要处理的列索引(从1开始):")
' 遍历选定列的每个单元格
For iRow = 1 To oTbl.Rows.Count
On Error Resume Next
Set oCell = oTbl.Cell(iRow, iCol)
On Error GoTo 0
' 如果成功获取到单元格对象
If Not oCell Is Nothing Then
ActiveDocument.Indexes.MarkEntry Range:=oCell.Range, Entry:=oCell.Range.Text
End If
Next iRow
Else
MsgBox "未能正确获取到选中的表格,请确保只选中了一个表格的有效内容。"
End If
Else
MsgBox "没有选中表格或表格中的单元格。"
End If
End Sub
'''