Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Need Help With Find

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JBNewsGroup - 16 Feb 2005 10:56 GMT
Hi,

I am working with WORD2000 VBA.

I am stepping through each item in a "master" document and updating tables
in a second document. In the "master" document there is a number *1.  The
table that is being updated has values like *1047A, *1064, *1077, etc.. The
goal is to find an exact match, or not, for *1.  Executing the Find I hit
each table value that has a *1xxx.  The following code is in a Function
procedure:

      -- set up table range --

     With SearchRange
          .Forward = True
         .MatchCase = True
         .MatchWholeWord = True
         .MatchWildCards = False

         SearchComplete = False
         Do
             .Execute FindText:=SearchText
             If .Found then
                If (SearchText = actual cell text without terminators) Then
                    RowNo = row number found by Execute
                    SearchComplete = True
               End If
            Else
               RowNo = 0
               SearchComplete = True
            End If
        Loop Until SearchComplete
     End With

     --- other code ---

How do I perform an Exact Match?  Is the Loop the only way to do it or am I
missing something?
I also tried using the Selection object but it seems that I have the same
problem.

Any help or suggestions is greatly appreciated. I would like to get rid of
the Loop if possible as the table data can change and there may be "tons" of
data that could have a hit (the "master" can also change).

Thanks in advance.

Jerry Bodoff
Helmut Weber - 16 Feb 2005 13:25 GMT
Hi Jerry,
this is the way I usually search a range,
but as I don't quite understand what you are heading for,
some kind of loop is required anyway,
an while ... wend is a loop, too.

Sub test8766()
Dim oRng As Range
Set oRng = ActiveDocument.Tables(1).Range
ResetSearch
With oRng.Find
  .Text = "*[0-9]{4}"
  .MatchWildcards = True
  While .Execute
     MsgBox oRng.Text
  Wend
End With
ResetSearch
End Sub

Public Sub ResetSearch()
With Selection.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Text = ""
  .Replacement.Text = ""
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  ' plus some more if needed
  .Execute
End With
End Sub

Note that .Text = "*[0-9]{4}" does not
regard whether a cell starts with the text
to be searched for or ends with that text,
or whether the text is found several times
in one cell.

Or do you want to stop the search, as soon as
one (1) match in a table was found and procede
with the next table?

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
JBNewsGroup - 16 Feb 2005 13:37 GMT
Hi Helmut,

Thanks for your reply.  Wildcards are not valid for the search, the Match
must be exact.  So I guess the the code I now have in place is the way to
go.  It is too bad that MS did not have a "MatchExact" property.  They gave
everything else.

Once again thanks.

Jerry Bodoff
> Hi Jerry,
> this is the way I usually search a range,
[quoted text clipped - 51 lines]
> Word XP, Win 98
> http://word.mvps.org/
Jay Freedman - 16 Feb 2005 20:55 GMT
Hi Jerry.

A wildcard search can still do exact matches, if you can pin down the
conditions well enough. Can I assume that the *1 you're looking for is
always followed by a space or punctuation? The wildcard zoo includes codes
for "start of word" and "end of word", so you may be able to use the
criterion

  .Text = "\*1>"

The asterisk has to be escaped with the backslash to look for an actual
asterisk, and the > means "end of word".

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org

> Hi Helmut,
>
[quoted text clipped - 61 lines]
>> Word XP, Win 98
>> http://word.mvps.org/
JBNewsGroup - 17 Feb 2005 07:34 GMT
Hi Jay,

The *1 is it. There is no punctuation or space after it.  Also, there may,
or may not be, an * preceding the data and all data is variable length
alpha-numeric. I will try the wild card approach. I am still a little
sketchy using all the wild card options but I will check them out and see
what else there is.  I am assuming that the end of word will work for table
cells. Thanks for replying and for the wild card hint.

Jerry Bodoff
> Hi Jerry.
>
[quoted text clipped - 74 lines]
> >> Word XP, Win 98
> >> http://word.mvps.org/
JBNewsGroup - 17 Feb 2005 09:58 GMT
Hi Jay,

I re-read the MVP article "Finding and replacing characters using
wildcards". It turns out that the wildcard string you suggested works like a
charm. I only have to worry about the first * as the data has been validated
for only one * at the beginning, if any at all. I finally got rid of the
loop that was slowing me down (1 to 3 tables may have to be searched).

Once again thanks for your help.

Jerry B

> Hi Jerry.
>
[quoted text clipped - 74 lines]
> >> Word XP, Win 98
> >> http://word.mvps.org/
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.