keeping the Selection.Find.Found property

M

Martin Müller

Dear experts,

I want to implement a loop to find certain strings within
two documents alternatively AND have a condition to exit
the loop. The intention is to figure out, if a certain
type of string, found in the first document, is present in
the other, continuing so until the end of the former
document is reached. As far as I have got, this requires
the command sequence
Selection.Find....
...
Selection.Find.Execute
(now a string behind the selection is read out and put
into a variable)
Windows(<second window>).Activate
Selection.Find.Text = <variable>
....
Selection.Find.Execute
Windwows(<former window>).Activate
(write the page number of the found string into the first
document)
all embedded within a loop
Now, since the method Selection.Find... must be used in
both the documents, the loop exit condition
Until Selection.Find.Found = False does not work in the
first document, neither the .Find.Execute boolean.
How can the Selection.Find.Found Property be kept for one
document, although I utilize a Selection.Find method also
in the second? By moving the search in the second to a
certain subroutine?
Best regards and thank you
Martin
 
H

Helmut Weber

Hi Martin,
how about that:
Public Sub FindBoth()
Dim aWord As Object
For Each aWord In Documents(1).Words
Documents(2).Select
With Selection.Find
.ClearFormatting
.Text = aWord
If .Execute Then
MsgBox aWord & " gibt's auch in doc 2"
End If
End With
Next
End Sub
Greetings from Bavaria, Germany
Helmut Weber
 
M

Martin Müller

A good idea, perfectly suited, if the string to be
searched is well-defined. However, the problem is, that I
like to find in the first document numbers with varying
lengths (varying numbers of digits) possibly even
containing a letter behind (e.g. 3, 23, 123A etc. (theser
are fig.numbers)); it means I have to look for any number
and check the following characters through
Selection.MoveRight Unit:=wdWord, Count:=1,
Extend:=wdExtend
and, having found one, look for it in the other document;
in short, actions have to be performed in both the
documents. Then the Selection.Find.Found property is,
however, cleared. Can it or any other condition be kept?
Best regards from Hessen
Martin
 
D

Doug Robbins - Word MVP

Hi Martin,

If they are Figure numbers, consider the use of a Wildcard search.

(Figure )([0-9A-Z]{1,})

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
 
M

Martin Müller

Possibly I cannot solve the problem, because I want to
read out the page number of the figure in the second
document through
Page = Str(Selection.Information
(wdActiveEndAdjustedPageNumber))
This means, as soon as I have found an entry (fig.number)
in the first document (list, 'survey of figures'), I like
to write into this document, next to this entry, the
corresponding page number, where the figure with this
number is situated in the second document. Within the loop
I therefore need the Selection-object twice, first to find
the strings in the first list, second to get the page-
information out of the other document. Is there another
way to get a page information than via
Selection.Information ?
Best regards
Martin

-----Original Message-----
Hi Martin,

If they are Figure numbers, consider the use of a Wildcard search.

(Figure )([0-9A-Z]{1,})

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
A good idea, perfectly suited, if the string to be
searched is well-defined. However, the problem is, that I
like to find in the first document numbers with varying
lengths (varying numbers of digits) possibly even
containing a letter behind (e.g. 3, 23, 123A etc. (theser
are fig.numbers)); it means I have to look for any number
and check the following characters through
Selection.MoveRight Unit:=wdWord, Count:=1,
Extend:=wdExtend
and, having found one, look for it in the other document;
in short, actions have to be performed in both the
documents. Then the Selection.Find.Found property is,
however, cleared. Can it or any other condition be kept?
Best regards from Hessen
Martin


.
 
H

Helmut Weber

Hi Martin,
I think, there are many ways to do this. The question is,
whether this is a unique task or whether is should be
repeated frequently. Just for fun, I had a closer look and
found this complication: A figure number may appear
repeatedly in doc(1) and as well repeatedly in doc(2).
Further, in theory, figure numbers may not well be
defined, as there may be lots of numbers in your document,
that are not figure numbers. At last, keeping the
Selection.find.found property seems to be irrelevant.
One could use ranges, or, as I did in the following,
put the expressions to search for in an array, search for
them in doc(2), and, if found, get the page, search for
them in doc(1) and add the text "page".
Here is my code, not a solution, but maybe a hint
in the right direction.
Public Sub FindBoth3()
Dim objWord As Object
Dim arrWord() As String
Dim intWord As Integer
Dim cntWord As Integer
Dim intPage As Integer
For Each objWord In Documents(1).Words
If IsFigure(Left(objWord, 1)) Then
intWord = intWord + 1
End If
Next
cntWord = intWord
ReDim arrWord(cntWord)
intWord = 0

For Each objWord In Documents(1).Words
If IsFigure(Left(objWord, 1)) Then
intWord = intWord + 1
arrWord(intWord) = objWord
End If
Next

Documents(2).Select
For intWord = 1 To cntWord
Selection.WholeStory
With Selection.Find
.Text = arrWord(intWord)
If .Execute Then
intPage = Selection.Information(1)
Documents(1).Select
With Selection.Find
.Text = arrWord(intWord)
.Execute
End With
Selection.Collapse direction:=wdCollapseEnd
Selection.TypeText Text:=" [" & intPage & "]"
End If
End With
Next
End Sub
Greetingts from Bavaria, Germany
Helmut Weber
 
H

Helmut Weber

Public Function IsFigure(ByVal aChr$) As Boolean
If aChr$ = "" Then
IsFigure = False
Exit Function
End If
If Asc(aChr) < 48 Or Asc(aChr) > 57 Then
IsFigure = False
Else
IsFigure = True
End If

End Function
 

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