【发布时间】:2017-09-01 20:34:05
【问题描述】:
我正在编写一个宏来将索引条目添加到 word 表中的条目中。一些单元格包含一个字符串,需要添加我已经设法完成的条目。例如,单元格包含“S875”。我为此使用了以下代码:
For Each oRow In oTable.Rows
If oRow.Cells.count = 4 Then
oTable.Cell(oRow.Index, 4).Select
Selection.Expand unit:=wdCell
oem = Left$(Selection.Text, Len(Selection.Text) - 2)
If (oem Like "*O.E.M*") Or (oem Like "*OEM*") Then
'ignore this row
Debug.Print oem
Else
ActiveDocument.Indexes.MarkEntry Range:=Selection.Range, Entry:=oem, _
EntryAutoText:=oem, CrossReference:="", CrossReferenceAutoText:="",
BookmarkName:="", Bold:=False, Italic:=False
End If
End If
Next oRow
但是我有一些需要添加两个或更多索引条目的单元格,例如 S875、876。我已将它们拆分为一个数组并可以循环遍历该数组,但我一直坚持如何设置要添加的范围索引条目。我所拥有的是:
If Len(oem) > 6 Then
oemArray() = Split(oem, ", ")
For i = LBound(oemArray) To UBound(oemArray)
'need to use Indexes.MarkEntry to add an index entry for each
' string in the array
Debug.Print oemArray(i)
Next i
End If
所以我认为我要么需要以某种方式将选择更改为数组上的每个条目,要么使用范围,但我不确定?
【问题讨论】: