Uniquely identify word

D

Dinko Deranja

Is it possible to uniquely identify a word in document. E.g. if I want to
extract all words in document to a database, and then use GoTo (or similar)
method to go to this exact word in document.
 
P

Peter Hewett

Hi Dinko Deranja

It's possible but I'm not sure it's a good idea! How are you going to keep your
database in sync with your document. Every time you save your document you have
to update the database. I'd like to know how long it'll take on a 600 page
document!

If you can deal with the above problems in addition to the documents BodyText
there are all of the other story ranges to consider. Such as Headers, Footers,
FootNotes, EndNotes etc.

You could use the Words collection object.

HTH + Cheers - Peter
 
D

Dinko Deranja

Peter Hewett said:
Hi Dinko Deranja

It's possible but I'm not sure it's a good idea! How are you going to keep your
database in sync with your document. Every time you save your document you have
to update the database. I'd like to know how long it'll take on a 600 page
document!

You are right, but the document will not be changed once it is scanned.
If you can deal with the above problems in addition to the documents BodyText
there are all of the other story ranges to consider. Such as Headers, Footers,
FootNotes, EndNotes etc.

I need only the body text of the document, for now.
You could use the Words collection object.

I will try. What I need is an easy way to reposition to that word when
necessary. So, if I have database fields ID and Text where ID is that unique
identifier, and text is the word itself, then I need to quickly jump to the
place in document where this word is, something like oDoc.GoTo(ID). Of
course, this identifyer has to be reliable (if the document hasn't changed).
 
P

Peter Hewett

Hi Dinko Deranja

Word has a "Words" document collection object. You might try that. You'll need
to test it to ensure that you like Words definition of a word (which can't be
changed). If Word returns words that you don't consider words then you can just
drop them from the database. You'll have holes, but it wont matter since the
holes represent document content you don't want.

HTH + Cheers - Peter
 
P

Peter Hewett

Hi Peter Hewett

I forgot to add, to select the original word, use something like this:

Public Sub SelectWord()
Dim lngIndex As Long

' Assign this value from your DB
lngIndex = databasevalue
ActiveDocument.Words(lngIndex).Select
End Sub

HTH + Cheers - Peter
 
D

Dinko Deranja

Peter Hewett said:
Hi Peter Hewett

I forgot to add, to select the original word, use something like this:

Public Sub SelectWord()
Dim lngIndex As Long

' Assign this value from your DB
lngIndex = databasevalue
ActiveDocument.Words(lngIndex).Select
End Sub

Thanks Peter, that is OK for selecting the word, but how to get it? The
situation is:

For each myWord in myDoc.Words
myDBIDfield = myWord.??
....
Next

So the problem now is how to find out the index value to put it in database?
 
P

Peter Hewett

Hi Dinko Deranja

There are a number of ways but this is the most efficient (fastest):

Public Sub WordIndex()
Dim rngWord As Word.Range
Dim clngWord As Long

For Each rngWord In ActiveDocument.Words
clngWord = clngWord + 1

' Do some thing with word and index
MsgBox clngWord & ", " & rngWord.Text
Next
End Sub

HTH + Cheers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top