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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find words in Word 1

Status
Not open for further replies.
Apr 10, 2000
155
US
We are flagging certain words in our docs for later creating bookmarks. Currently we have done this by typing [[nameoffield]]. The nameoffield may be lots of different possibilities. I would like to create a procedure to go through a doc and pull out all of the words it finds between the [[...]].

Cannot figure it out. Any thoughts?

Rick
 
If you are looking for a VBA (a macro) to do this, then you should be posting in the VBA forum. Here is something that may get you started. If you want more, then start a thread in the VBA forum.
Code:
Sub FindYaddaYadda()
Dim msg As String
Dim r As Range
Set r = ActiveDocument.Range
With r.Find
    .ClearFormatting
    .MatchWildcards = True
    .Text = "\[\[*\]\]"
    Do While (.Execute(Forward:=True) = True) = True
        msg = msg & Mid(r.Text, 3, Len(r.Text) - 4) & vbCrLf
    Loop
End With
Set r = Nothing
MsgBox msg
End Sub

Say you have: [[harry]], [[whatever]], [[something here]] in the document, then the above will display a messagebox:

harry
whatever
something here

I did this into a messagebox, as I do not know what you mean by "pull out all the words". Do you mean delete them? Do you mean list them (which I did into a message box)? Do you mean perform some other action on them?

Whatever.

You may also consider using regular expressions.

I sure would like to know what you mean by "We are flagging certain words in our docs for later creating bookmarks."

Flagged? How? Just by putting [[ ]] around them? Do you want to find those [[xxxxxxxx]], and turn them into bookmarks? This would be very easy to do.

I am uneasy about the use of "field", as in nameoffield. ARE they fields???? This would be something different.

faq219-2884

Gerry
My paintings and sculpture
 
Thanks, I was able to take this and plug it into my procedure that loops through all the docs in a directory, search the files and then type out the filenames and bookmark names in a new file.

I really appreciate what you did here. Thank you.

Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top