Sub Array_Test()
'A basic Word macro modified by Greg Maxey, http://gregmaxey.com/word_tips.html, 12/8/2017
'*** Questions\Comments
'1. Why do you dim some variables but not others?
Dim oRng As Range
'2. If j and k are confusing, why do you use them?
'Dim j As Long
'Dim k As Long
Dim lngIndex As Long
Dim oProduct 'dimmed as variant
'3. As ArraySortMethods(4,5,6) appears to have no bearing on the desired result, why is it there?
'4. The following statement, in addition to the apparently superfluous Array(4,5,6) contains variant
'variables A, B and C (with no value). Even if your code worked the replacement values would be
'nothing, nothing and nothing.
'oProduct = Array(Array(1, 2, 3), Array(A, B, C), Array(4, 5, 6))
'5. Here A, B and C are replaced with literal string values A B and C
oProduct = Array(Array(1, 2, 3), Array("A", "B", "C"))
'k = 1
For lngIndex = LBound(oProduct) To UBound(oProduct(0))
Set oRng = ActiveDocument.Range
With oRng.Find
' Do While .Execute(oProduct(0)(lngIndex), MatchWholeWord:=True)
' oRng.Text = oProduct(1)(lngIndex)
' oRng.Collapse 0
' Loop
'Or
.Execute FindText:=oProduct(0)(lngIndex), MatchWholeWord:=True, ReplaceWith:=oProduct(1)(lngIndex), Replace:=wdReplaceAll
End With
Next lngIndex
lbl_Exit:
Exit Sub
End Sub