Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    May 2001
    Location
    MIA (takittodahous), Florida, USA
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cell Value based 'Find' (Word2002)

    I have a macro that uses the values in cells of a table as variables in a Find function. I'm trying to highlight all matching existances of the values. The variables assign ok, except that it's pulling the character for the column return when capturing the text. Since the strings I'm looking to match don't have that 'return', my Find functions end up identifying nothing.

    Is there a way to limit what I'm pulling from the cell for the variable? Or is there a better way to think about this that I'm missing?

    Here's the code:

    For Each aCell In ActiveDocument.Tables(1).Columns(1).Cells
    Acc = CleanString(aCell.Range.Text)
    Selection.Find.Execute
    With Selection.Find
    .Text = Acc
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With

    Selection.Range.HighlightColorIndex = wdRed


    PS - that CleanString was an attempt to remove the return.... didn't work [img]/forums/images/smilies/sad.gif[/img]

    Thanks for your help.

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Cell Value based 'Find' (Word2002)

    There's probably a less long-winded way to do this, but see the following code example for a way to strip the end of cell marker from the text string returned from the cell:

    <pre>Dim lngCellLen As Long
    Dim strCellText As String

    lngCellLen = Len(ActiveDocument.Tables(1).Range.Cells(1).Range)
    strCellText = _
    Left$(ActiveDocument.Tables(1).Range.Cells(1).Rang e.Text, lngCellLen - 2)
    MsgBox strCellText
    </pre>

    Gary

  3. #3
    Star Lounger
    Join Date
    May 2001
    Location
    MIA (takittodahous), Florida, USA
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Cell Value based 'Find' (Word2002)

    Yeah - the long-winded code was from using the macro recorder (yuk...) But since I'm VBA Word novice, it was an ok starting point...

    Thanks for the strip hints!

Posting Permissions

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