I'm writing a macro to add index entries to entries in tables in word. Some cells contain a single string that needs the entry added to which I've managed to do. Eg, cell contains 'S875'. I've used the following code for this:
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
But I've got some cells that need two or more index entries added, eg, S875, 876. I've split these into an array and can loop through the array but am stuck on how to set the Range to add the index entries. What I have is:
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
So I think I either need to somehow change the Selection to each entry on the array or use the Range but I'm not sure exactly?