Solved

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

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
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 …
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

628 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