Searching for matches between documents

S

Sam

Hi,
I'm trying to write a macro that will search through the
document for any sentences that are found in a second
document, containing tab-seperated sentances. How can I do
this?

Thanks!
 
J

Jezebel

As a start --

Dim pSentence as Word.Range
Dim pDocText as string

pDocText = TargetDoc.Range.Text
For each pSentence in SourceDoc.Sentences
if instr(pDocText, pSentence.Text) > 0 then
.... YES, FOUND
end if
Next

You might need to deal with upper-case/lower-case issues.
 
S

Sam

Hi Jezebel, thatnks for the reply.

How does that code take into account tab-separated text?
Some of the things I'd be looking for would be words, some
multiple senences, but they would all be separated by tabs.

Thanks!
 
J

Jezebel

It ignores it. All it's doing is checking whether a given piece of text (ie
a sentence) from document 1 occurs in document 2. How the sentences in doc 2
are organised and formatted is irrelevant. You may get some spurious hits if
a sentence in doc 1 is a subset of a sentence in doc 2. And you'll miss any
matches if the sentence in one doc uses tabs where the other uses spaces.
You might get a better result if your first replace all white space in both
documents with a single space character.
 
S

Sam

Hmmm, but what I wanted (I didn't say this before because
I though I'd keep it simple - silly me) was to have it
search for sentence(s) that are on one side of the second
document and add comments to them based on sentance(s) on
the other side.
So if my second document looked like

<1> [tab] <2> [Enter]
<3> [tab] <4> [Enter]

it would add the comment <2> to all instances of <1>, and
ditto for 3 and 4.

Sorry for not saying this all in the first place, and
thanks for your help!
 
J

Jezebel

Yes, that's a *much* more complicated requirement. do-able, but it would
take some planning. Are the documents very large, and do you need to do this
more than once?


Sam said:
Hmmm, but what I wanted (I didn't say this before because
I though I'd keep it simple - silly me) was to have it
search for sentence(s) that are on one side of the second
document and add comments to them based on sentance(s) on
the other side.
So if my second document looked like

<1> [tab] <2> [Enter]
<3> [tab] <4> [Enter]

it would add the comment <2> to all instances of <1>, and
ditto for 3 and 4.

Sorry for not saying this all in the first place, and
thanks for your help!

-----Original Message-----
It ignores it. All it's doing is checking whether a given piece of text (ie
a sentence) from document 1 occurs in document 2. How the sentences in doc 2
are organised and formatted is irrelevant. You may get some spurious hits if
a sentence in doc 1 is a subset of a sentence in doc 2. And you'll miss any
matches if the sentence in one doc uses tabs where the other uses spaces.
You might get a better result if your first replace all white space in both
documents with a single space character.






.
 
S

Sam

Document 2 (with the list of sentences) would probably
only be about two or three pages at most, but would
definately be used many times (hence making the macro).

Is it really much harder? I had assumed that I could just
pick out a sentence from the beginning to the tab, and
then use that in my search string. I guess it's easier
said than done... :)

-----Original Message-----
Yes, that's a *much* more complicated requirement. do- able, but it would
take some planning. Are the documents very large, and do you need to do this
more than once?


Sam said:
Hmmm, but what I wanted (I didn't say this before because
I though I'd keep it simple - silly me) was to have it
search for sentence(s) that are on one side of the second
document and add comments to them based on sentance(s) on
the other side.
So if my second document looked like

<1> [tab] <2> [Enter]
<3> [tab] <4> [Enter]

it would add the comment <2> to all instances of <1>, and
ditto for 3 and 4.

Sorry for not saying this all in the first place, and
thanks for your help!

-----Original Message-----
It ignores it. All it's doing is checking whether a
given
piece of text (ie
a sentence) from document 1 occurs in document 2. How
the
sentences in doc 2
are organised and formatted is irrelevant. You may get some spurious hits if
a sentence in doc 1 is a subset of a sentence in doc 2. And you'll miss any
matches if the sentence in one doc uses tabs where the other uses spaces.
You might get a better result if your first replace all white space in both
documents with a single space character.



Hi Jezebel, thatnks for the reply.

How does that code take into account tab-separated text?
Some of the things I'd be looking for would be words, some
multiple senences, but they would all be separated by tabs.

Thanks!

-----Original Message-----
As a start --

Dim pSentence as Word.Range
Dim pDocText as string

pDocText = TargetDoc.Range.Text
For each pSentence in SourceDoc.Sentences
if instr(pDocText, pSentence.Text) > 0 then
.... YES, FOUND
end if
Next

You might need to deal with upper-case/lower-case issues.


Hi,
I'm trying to write a macro that will search
through
the
document for any sentences that are found in a second
document, containing tab-seperated sentances. How can I
do
this?

Thanks!


.



.


.
 
K

Keith Miller

If your second document is essentially data file of search text and comments which are tab
delimited, I think it would be easier to convert it to a two-column table and then you could loop
based on row count, searching for the text in (rownum, 1) and inserting the comment from (rownum,
2). This would avoid searching what is essentially a static document (& probably make it easier to
maintain).

The following uses the search code from this recent post:

Dim r As Range
Dim mySearchText As String
Dim myCommentText As String

for i = 1 to DataDocument.tables(1).Rows.Count

mySearchText = DataDocument.tables(1).cell(i,1).Range.Text
myCommentText = DataDocument.tables(1).cell(i,2).Range.Text

Set r = ActiveDocument.Range
With r.Find
.Text = mySearchText
.Forward = True
.Wrap = wdFindStop
.MatchWholeWord = True
Do While .Execute
ActiveDocument.Comments.Add Range:=r, _
Text:=myCommentText
Loop
End With

Next i





Sam said:
Document 2 (with the list of sentences) would probably
only be about two or three pages at most, but would
definately be used many times (hence making the macro).

Is it really much harder? I had assumed that I could just
pick out a sentence from the beginning to the tab, and
then use that in my search string. I guess it's easier
said than done... :)

-----Original Message-----
Yes, that's a *much* more complicated requirement. do- able, but it would
take some planning. Are the documents very large, and do you need to do this
more than once?


Sam said:
Hmmm, but what I wanted (I didn't say this before because
I though I'd keep it simple - silly me) was to have it
search for sentence(s) that are on one side of the second
document and add comments to them based on sentance(s) on
the other side.
So if my second document looked like

<1> [tab] <2> [Enter]
<3> [tab] <4> [Enter]

it would add the comment <2> to all instances of <1>, and
ditto for 3 and 4.

Sorry for not saying this all in the first place, and
thanks for your help!


-----Original Message-----
It ignores it. All it's doing is checking whether a given
piece of text (ie
a sentence) from document 1 occurs in document 2. How the
sentences in doc 2
are organised and formatted is irrelevant. You may get
some spurious hits if
a sentence in doc 1 is a subset of a sentence in doc 2.
And you'll miss any
matches if the sentence in one doc uses tabs where the
other uses spaces.
You might get a better result if your first replace all
white space in both
documents with a single space character.



Hi Jezebel, thatnks for the reply.

How does that code take into account tab-separated text?
Some of the things I'd be looking for would be words,
some
multiple senences, but they would all be separated by
tabs.

Thanks!

-----Original Message-----
As a start --

Dim pSentence as Word.Range
Dim pDocText as string

pDocText = TargetDoc.Range.Text
For each pSentence in SourceDoc.Sentences
if instr(pDocText, pSentence.Text) > 0 then
.... YES, FOUND
end if
Next

You might need to deal with upper-case/lower-case
issues.


Hi,
I'm trying to write a macro that will search through
the
document for any sentences that are found in a second
document, containing tab-seperated sentances. How
can I
do
this?

Thanks!


.



.


.
 
W

Word Heretic

G'day "Sam" <[email protected]>,

Hey Sambo! Here's a really _cool_ idea. How about you post *exactly
what u r after* and _we_ will try and match you up with specific
_free_ help. If you need a solution urgently/succintly, please do not
feel shy to embarrass me with an email offlist.


Sam said:
Document 2 (with the list of sentences) would probably
only be about two or three pages at most, but would
definately be used many times (hence making the macro).

Is it really much harder? I had assumed that I could just
pick out a sentence from the beginning to the tab, and
then use that in my search string. I guess it's easier
said than done... :)

-----Original Message-----
Yes, that's a *much* more complicated requirement. do- able, but it would
take some planning. Are the documents very large, and do you need to do this
more than once?


Sam said:
Hmmm, but what I wanted (I didn't say this before because
I though I'd keep it simple - silly me) was to have it
search for sentence(s) that are on one side of the second
document and add comments to them based on sentance(s) on
the other side.
So if my second document looked like

<1> [tab] <2> [Enter]
<3> [tab] <4> [Enter]

it would add the comment <2> to all instances of <1>, and
ditto for 3 and 4.

Sorry for not saying this all in the first place, and
thanks for your help!


-----Original Message-----
It ignores it. All it's doing is checking whether a given
piece of text (ie
a sentence) from document 1 occurs in document 2. How the
sentences in doc 2
are organised and formatted is irrelevant. You may get
some spurious hits if
a sentence in doc 1 is a subset of a sentence in doc 2.
And you'll miss any
matches if the sentence in one doc uses tabs where the
other uses spaces.
You might get a better result if your first replace all
white space in both
documents with a single space character.



Hi Jezebel, thatnks for the reply.

How does that code take into account tab-separated text?
Some of the things I'd be looking for would be words,
some
multiple senences, but they would all be separated by
tabs.

Thanks!

-----Original Message-----
As a start --

Dim pSentence as Word.Range
Dim pDocText as string

pDocText = TargetDoc.Range.Text
For each pSentence in SourceDoc.Sentences
if instr(pDocText, pSentence.Text) > 0 then
.... YES, FOUND
end if
Next

You might need to deal with upper-case/lower-case
issues.


Hi,
I'm trying to write a macro that will search through
the
document for any sentences that are found in a second
document, containing tab-seperated sentances. How
can I
do
this?

Thanks!


.



.


.

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
Email (e-mail address removed)
Products http://www.geocities.com/word_heretic/products.html

Replies offlist may require payment.
 

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