0
我正在编写一个宏以将索引条目添加到表中的条目中。有些单元格包含一个需要添加条目的字符串,我已经设法完成该条目。例如,单元格包含'S875'。我用下面的代码是:如何将数组中的字符串设置为Word中的范围VBA
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
所以,我认为我要么需要在选择某种方式改变为每个条目阵列上或使用范围,但我不知道到底是什么?