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 / September 2007

Tip: Looking for answers? Try searching our database.

Help with Repeated Find and Select in a Specified Table Range (Col

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dejones923 - 20 Sep 2007 16:54 GMT
I have an established range in a table.  In that range there is verbiage
surrounded by parenthesis like (abc) (defghi) (jklm) etc.  I would like to
select each instance in the range to do something with it before going to the
next row.  

Can anyone help with this.

Sub GetVerbiage()

   Dim totCount As Integer,  i As Integer, myVerbiage As String,
rngToSearch As   Range, rngResult As Range, intRow As Integer
   
         totCount = ActiveDocument.Tables(23).Rows.Count
         For i = 14 To totCount
               Set rngToSearch =
ActiveDocument.Tables(23).Rows(i).Cells(7).Range
               Set rngResult = rngToSearch.Duplicate
               With rngResult.Find
                   .ClearFormatting
                   .Text = "\(*\)"
                   .Forward = True
                   .MatchWildcards = True
                   .Wrap = wdFindContinue
                   .Execute
               End With

               If rngResult.Find.Found Then
                  'do something here
               End If
 
                 'At this point there is other verbiage in the range that I
would like to     look at and maybe do something with it but the code jumps
to the next i.  How do I get it to look at the next instance where there is
verbiage surronded by parenthesis like (Now is the time1)  (Now is the time2)'

           Next i
End Sub

Signature

Thank you
DJ

Jay Freedman - 20 Sep 2007 18:30 GMT
Replace these lines

                   .Execute
               End With

               If rngResult.Find.Found Then
                  'do something here
               End If

with these lines

                   Do While .Execute And rngResult.InRange(rngToSearch)
                         'do something here
                   Loop
               End With

The .Execute method returns a boolean result that is always exactly the same
as the value of rngResult.Find.Found. A side effect of the .Execute is that
rngResult is redefined to cover only the found text. The InRange method
checks that the found text is within rngToSearch, so the loop stops after
processing the last occurrence within the search range.

If the processing that occurs inside the loop changes the size or contents
of rngResult, then the last statement before the Loop line must set
rngResult to the end of its original location, so the next iteration starts
searching from that point. Failure to do this can result in an infinite loop
if it causes the search to find the same location again. If all you're doing
is reformatting or copying the range, this step isn't necessary.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> I have an established range in a table.  In that range there is
> verbiage surrounded by parenthesis like (abc) (defghi) (jklm) etc.  I
[quoted text clipped - 34 lines]
>            Next i
> End Sub
dejones923 - 20 Sep 2007 20:20 GMT
Thank's Jay, this was "right on point" and resolved my issue.
Signature

Thank you
DJ

> Replace these lines
>
[quoted text clipped - 63 lines]
> >            Next i
> > End Sub
 
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.