Solved

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

Posted on 2010-08-19
3
387 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

760 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

22 Experts available now in Live!

Get 1:1 Help Now