I'm writing a macro to take input from a .txt file wordlist into a string variable, search the document for instances of that word, and mark each instance as an index entry. The code I came up with is as follows, using the variable "term" as the term to be marked:
The trouble is that this only marks the first instance of each term in the document. How would I go about having it scan the entire document and mark each instance of the term?
While I'm at it, I have another stupid question for you (it's been forever since I've written vb code). Let's say my wordlist file, which is parsed by commas, is opened for input as #1, and I want to input it into dynamic string array "term(x)". How would I go about defining x as the number of terms in the wordlist, then inputting the wordlist into the array from 1 to x sequentially? In other words, I want to count the number of terms in the list, assign that to a variable, and then input the terms from the file into an array.
Your help is appreciated. Thanks!
Code:
With Selection.Find
.Text = term
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
ActiveWindow.ActivePane.View.ShowAll = True
ActiveDocument.Indexes.MarkEntry Range:=Selection.Range, Entry:= _
term, EntryAutoText:=term, CrossReference:="", _
CrossReferenceAutoText:="", BookmarkName:="", Bold:=False, Italic:=False
End If
While I'm at it, I have another stupid question for you (it's been forever since I've written vb code). Let's say my wordlist file, which is parsed by commas, is opened for input as #1, and I want to input it into dynamic string array "term(x)". How would I go about defining x as the number of terms in the wordlist, then inputting the wordlist into the array from 1 to x sequentially? In other words, I want to count the number of terms in the list, assign that to a variable, and then input the terms from the file into an array.
Your help is appreciated. Thanks!