Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word macro: Selection.Find.Execute and file input

Status
Not open for further replies.

LMSguy

Programmer
Aug 2, 2007
5
US
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:

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
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!
 
This appears to be straight VBA. You will do better with VBA (rather than VB6) questions in forum707

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top