Also, some of these green highlighted words begin with a special character
(caret ^) denoting that they are already updated. If possible, it would be
really great if I could exclude those words from the "find next green
highlighted" process.
Thanks in advance!
--
Alan
Sub Test()
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Set oRng1 = ActiveDocument.Range
Set oRng2 = Selection.Range
oRng1.Start = oRng2.End
Continue:
With oRng1.Find
.Highlight = True
.Execute
oRng1.Select
If oRng1.Characters.First = "^" Then
oRng1.Collapse wdCollapseEnd
GoTo Continue
Else
Selection.Collapse wdCollapseStart
End If
End With
End Sub
A couple of minor nits:
1) The document is a mixture of text in paragraphs and in tables. It
doesn't want to jump to the next line of a table but keeps scanning the same
row of the table.
2) When it gets to the end of the document, it seems to hang up and I have
to cntrl-brk. Any code to insert to recognize the end and shut off the macro?
Enhancement request:
Instead of the I-beam ending up in front of the word, can we select the word
instead?
--
Alan
As for the rest:
Sub Test()
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Set oRng1 = ActiveDocument.Range
Set oRng2 = Selection.Range
oRng1.start = oRng2.End
Continue:
With oRng1.Find
.MatchWildcards = True
.Highlight = True
.Execute
oRng1.Select
If oRng1.Characters.First = "^" Or _
oRng1.HighlightColorIndex <> wdBrightGreen Then
oRng1.Collapse wdCollapseEnd
If oRng1.End + 1 = ActiveDocument.End Then Exit Sub
GoTo Continue
' Else
' Selection.Collapse wdCollapseStart
End If
End With
End Sub
Note: If you have the Tools>Options>Edit>Typing Replaces Selection set then
if you start typing with the word selected, it will lose the highlighting.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
adgorn wrote:
> WOW, it works - carets, mixed highlighting and all! Thanks.
>
> A couple of minor nits:
> 1) The document is a mixture of text in paragraphs and in tables. It
> doesn't want to jump to the next line of a table but keeps scanning
> the same row of the table.
> 2) When it gets to the end of the document, it seems to hang up and I
> have
> to cntrl-brk. Any code to insert to recognize the end and shut off
> the macro?
>
> Enhancement request:
> Instead of the I-beam ending up in front of the word, can we select
> the word instead?
>
>
Sub StepThroughRange()
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Dim oRowIndex As Long
Dim oColIndex As Long
Set oRng1 = ActiveDocument.Range
Set oRng2 = Selection.Range
oRng1.start = oRng2.End
If Not oRng2.Information(wdWithInTable) Then
Continue:
With oRng1.Find
.Highlight = True
.Execute
oRng1.Select
If oRng1.Characters.First = "^" Or _
oRng1.HighlightColorIndex <> wdBrightGreen Then
oRng1.Collapse wdCollapseEnd
If oRng1.End + 1 = ActiveDocument.Range.End Then
Selection.Collapse wdCollapseEnd
Exit Sub
End If
GoTo Continue
Else
Selection.Collapse wdCollapseStart
End If
End With
Else
Continue2:
oRowIndex = Selection.Information(wdStartOfRangeRowNumber)
oColIndex = Selection.Information(wdStartOfRangeColumnNumber)
Set oRng1 = Selection.Tables(1).Cell(oRowIndex, oColIndex).Range
Set oRng2 = Selection.Range
oRng1.MoveEnd wdCharacter, -1
oRng1.start = oRng2.End
With oRng1.Find
.Highlight = True
.Execute
oRng1.Select
If oRng1.Characters.First = "^" Or _
oRng1.HighlightColorIndex <> wdBrightGreen Then
oRng1.Collapse wdCollapseEnd
If oRng1.End + 1 = Selection.Tables(1).Cell(oRowIndex,
oColIndex).Range.End Then
Selection.Collapse wdCollapseEnd
Selection.Move wdCharacter, 1
End If
If Selection.Range.End + 1 <> Selection.Tables(1).Range.End Then
GoTo Continue2
Else
GoTo Continue
End If
Else
Selection.Collapse wdCollapseStart
End If
End With
End If
End Sub
Thanks.
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
adgorn wrote:
> Works pretty well and will be useful, but still fails to find all
> instances w/i the tables. I'm sure you have other things you would
> prefer to do, but I'd be happy to send you a document to test/debug
> this with. Thank you very much for your efforts.
>
Sub StepThroughRange()
Dim oRng1 As Word.Range
Dim oRng2 As Word.Range
Dim oRowIndex As Long
Dim oColIndex As Long
Set oRng1 = ActiveDocument.Range
Set oRng2 = Selection.Range
oRng1.start = oRng2.End
Do
NextRow:
If oRng2.Information(wdWithInTable) Then
Set oRng2 = Selection.Range
oRowIndex = Selection.Information(wdStartOfRangeRowNumber)
oColIndex = Selection.Information(wdStartOfRangeColumnNumber)
On Error GoTo Handler
Set oRng1 = Selection.Tables(1).Cell(oRowIndex, oColIndex).Range
oRng1.MoveEnd wdCharacter, -1
oRng1.start = oRng2.End
With oRng1.Find
.Highlight = True
.Execute
oRng1.Select
If oRng1.Characters.First = "^" Or _
oRng1.HighlightColorIndex <> wdBrightGreen Then
oRng1.Collapse wdCollapseEnd
If oRng1.End + 1 = Selection.Tables(1).Cell _
(oRowIndex, oColIndex).Range.End Then
Selection.Collapse wdCollapseEnd
Selection.Move wdCharacter, 1
End If
If Selection.Range.End + 1 = Selection.Tables(1).Range.End Then
Selection.Move wdCharacter, 1
Set oRng2 = Selection.Range
Exit Do
End If
Else
Selection.Collapse wdCollapseStart
Exit Do
End If
End With
Else
Exit Do
End If
Loop
If Not oRng2.Information(wdWithInTable) Then
With oRng1.Find
.Highlight = True
Do
.Execute
oRng1.Select
If oRng1.Information(wdWithInTable) Then Exit Sub
If oRng1.Characters.First = "^" Or _
oRng1.HighlightColorIndex <> wdBrightGreen Then
oRng1.Collapse wdCollapseEnd
If oRng1.End + 1 = ActiveDocument.Range.End Then
Selection.Collapse wdCollapseEnd
Exit Sub
End If
Else
Selection.Collapse wdCollapseStart
Exit Do
End If
Loop
End With
End If
Exit Sub
Handler:
If Err.Number = 5941 Then
Selection.Move wdCharacter, 1
Resume NextRow