Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 395
  • Last Modified:

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

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
eshurak
Asked:
eshurak
  • 2
1 Solution
 
insaneCFCCommented:
If Not Intersect(SearchRange, ExcludeField) Is Nothing Then
0
 
eshurakAuthor Commented:
Thanks, but Intersect is only in Excel and I'm using Word.  Is there a Word equivalent?
0
 
eshurakAuthor Commented:
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now