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 / March 2006

Tip: Looking for answers? Try searching our database.

Need VBA code to find text until end of document is reached

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GlennMc - 24 Mar 2006 20:03 GMT
I'm using Word 2003.  I have a for next loop to search through indexes { XE "
"} in my document.  I'm using a find statement to find the " XE ", store the
string in a variable, compare it to the next found string, and delete if it
is a duplicate.  The number of indexes in the document will vary. How can I
have the code loop until the end of the document is reached.  I don't know
the syntax to use, if I can create a range based on words or indexes, or
count the number of indexes first and then use a for next loop.
Signature

GlennMc

Greg - 24 Mar 2006 20:20 GMT
GlennMc.

You should  be able to use .Wrap = wdFindStop.

Here is an example:

Sub Test()
Dim orng As Range
Set orng = ActiveDocument.Range
With orng.Find
.Text = "some text"
.Wrap = wdFindStop
Do While .Execute
  If .Found Then
    orng.Font.Color = wdColorBlue
  End If
Loop
End With
End Sub
Dave Lett - 24 Mar 2006 22:15 GMT
Hi Glenn,

You might find your task easier if you use the fields collection, as in the
following example:

Dim iFld As Integer
Dim sCurField As String
Dim sPrevField As String
sPrevField = ""
For iFld = ActiveDocument.Fields.Count To 1 Step -1
   If ActiveDocument.Fields(iFld).Type = wdFieldIndexEntry Then
       sCurField = ActiveDocument.Fields(iFld).Code
       If sCurField = sPrevField Then
           ActiveDocument.Fields(iFld).Delete
       End If
       sPrevField = ActiveDocument.Fields(iFld).Code
   End If
Next iFld

HTH,
Dave
> I'm using Word 2003.  I have a for next loop to search through indexes {
> XE "
[quoted text clipped - 7 lines]
> the syntax to use, if I can create a range based on words or indexes, or
> count the number of indexes first and then use a for next loop.
GlennMc - 26 Mar 2006 23:58 GMT
Very slick Dave.  Thanks.  
Signature

GlennMc

> Hi Glenn,
>
[quoted text clipped - 28 lines]
> > the syntax to use, if I can create a range based on words or indexes, or
> > count the number of indexes first and then use a for next loop.
 
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.