Solved

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

Posted on 2010-08-19
3
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

710 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