Solved

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

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide vba in gp 7 95
Word 2010 assign Hyperlink to Sub code 5 19
Find fonts in Word 2010 32 28
vba - Word save error 11 10
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
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…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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