Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Mar 2008
    Location
    Frederick, Maryland, USA
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Referencing Multiple Find Ranges (Word 2003)

    I am attempting to walk through a word table looking at content of two different cells through one iteration. I get what is expected on the first table cell, but it seems as though the range is never changed for me to get the expected result form the 2nd cell. The range continues to look at the content in cell 1.
    What am I doing wrong here?

    With ActiveDocument
    For t = 1 To TotTbls
    If .Tables(t).Columns.Count = 8 Then
    TotRows = .Tables(t).Rows.Count
    For r = 3 To TotRows
    Set cellRng1 = .Tables(t).Rows®.Cells(1).Range
    Set cellRng2 = .Tables(t).Rows®.Cells(2).Range

    With cellRng1.Find
    .ClearFormatting
    .Text = "(*)"
    .Forward = True
    .MatchWildcards = True
    .Wrap = wdFindContinue
    .Execute
    If .Found Then
    Debug.Print cellRng1.Text
    myItemRef = Mid(cellRng1.Text, 2, Len(cellRng1.Text) - 2)
    Debug.Print myItemRef
    End If
    End With

    With cellRng2.Find
    .ClearFormatting
    .Text = "[-]"
    .Forward = True
    .MatchWildcards = True
    .Wrap = wdFindContinue
    .Execute
    If .Found Then
    Debug.Print "found it"
    Debug.Print cellRng2.Text
    Else
    Debug.Print "did not find it"
    End If
    End With
    Next r
    End If
    Next t
    End With

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Referencing Multiple Find Ranges (Word 2003)

    Because you have .Wrap = wdFindContinue the search is not limited to the cell range. Try replacing both instances with

    .Wrap = wdFindStop

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •