Solved

Using VBA how do I test if range is part of a field

Posted on 2010-08-19
3
388 Views
Last Modified: 2013-11-10
Hello,

In Word 2003 I need to be able to test whether the text in a range is included in a field using VBA.

So the field is { XE "Agreement" } (this is an index marked field)

My code below is search for words that are enclosed in quotes, but I want it to exclude the ones that are part of a field.  So in the code below SearchRange will equal "Agreement".

Thanks for your help.
With SearchRange.Find



    .Text = Chr(147) & Chr(42) & Chr(148)

     .MatchWildcards = True

End With

Do While SearchRange.Find.Execute

    If SearchRange.Words.Count < 8 Then

        SearchRange.Select

        Debug.Print SearchRange & " Page - " & GetPageNumber(SearchRange) _

        & " Section - " & SearchRange.Paragraphs(1).Range.ListFormat.ListString

    End If

Loop

Open in new window

0
Comment
Question by:eshurak
  • 2
3 Comments
 
LVL 2

Expert Comment

by:insaneCFC
ID: 33482515
If Not Intersect(SearchRange, ExcludeField) Is Nothing Then
0
 
LVL 3

Author Comment

by:eshurak
ID: 33486269
Thanks, but Intersect is only in Excel and I'm using Word.  Is there a Word equivalent?
0
 
LVL 3

Accepted Solution

by:
eshurak earned 0 total points
ID: 33505652
I'm using the code below.  I should have thought of that sooner.
If ActiveDocument.Range(SearchRange.Start - 4, SearchRange.Start - 2) <> "XE" Then

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now