I'm not very familiar with working with arrays, so I'm hoping you can help.
I have some code that is building an array of text inside my document that is contained in brackets and is the length of one word. I want to add another condition that checks to see if I've already got that word in my array, and if so, skip.
Below is my code - I've placed commented text where I'd need this to go : '''''if strWord already exists in this array then skip over
How would I do that?
Function ReturnBracketArray() As String()
Dim strWord As String
Dim aBracketText() As String
Dim iCount As Long
Dim lngIndex As Long
Dim vSplit As Variant
Dim bTest As Boolean
On Error GoTo ReturnArray_Err
lngIndex = 0
Set objdoc = ActiveDocument
Set objSelection = objdoc.Range
objSelection.Find.Forward = True
objSelection.Find.MatchWildcards = True
objSelection.Find.Text = "\(*\)"
Do While True
If objSelection.Find.Found Then
strWord = objSelection.Text
strWord = Replace(Replace(strWord, "(", ""), ")", "")
strWord = Replace(Replace(strWord, Chr(145), ""), Chr(146), "")
ReDim aBracketText(0 To 2)
bTest = CountWords(strWord, iCount, vSplit)
If iCount < 2 Then
'''''if strWord already exists in this array then skip over
aBracketText(lngIndex) = strWord
lngIndex = lngIndex + 1
' Resize to current value of lngIndex - 1.
ReDim Preserve aBracketText(0 To lngIndex - 1)
ReturnBracketArray = aBracketText
' If upper bound is exceeded, enlarge array.
If Err.Number = 9 Then ' Subscript out of range
' Double the size of the array.
ReDim Preserve aBracketText(lngIndex * 2)
MsgBox "An unexpected error has occurred!", vbExclamation
Function CountWords(sInput As String, iWords As Long, vWords As Variant) As Boolean
vWords = Split(sInput, " ")
iWords = UBound(vWords) + 1 - LBound(vWords)
CountWords = True