S
Sahana
I m trying to find the word "done" which appear as last word in every
list. THe macro functions well but displays two comment boxes instead
of one.
Can someone help me correct this code?
Try the data as
There are various forums as follows:
• Discussion and forums
• Main done
• Help
Code would be
Sub FindInLists()
Dim i As Long
Dim j As Long
Dim pos As Integer
Dim searchText As String
Dim myRange As Range
searchText = "done"
With ActiveDocument
For j = 1 To .Lists.Count
For i = 1 To .Lists(j).ListParagraphs.Count
Set myRange = .Lists(j).ListParagraphs(i).Range
pos = InStrRev(myRange.Text, searchText, -1, _
vbTextCompare)
If pos > Len(myRange.Text) - 6 Then
myRange.Start = myRange.Start + pos - 1
myRange.End = myRange.Start + Len(searchText) - 4
myRange.Select
Selection.comments.Add _
Range:=Selection.Range, Text:="Please use noun
or plural form"
End If
Next
Next
End With
End Sub
list. THe macro functions well but displays two comment boxes instead
of one.
Can someone help me correct this code?
Try the data as
There are various forums as follows:
• Discussion and forums
• Main done
• Help
Code would be
Sub FindInLists()
Dim i As Long
Dim j As Long
Dim pos As Integer
Dim searchText As String
Dim myRange As Range
searchText = "done"
With ActiveDocument
For j = 1 To .Lists.Count
For i = 1 To .Lists(j).ListParagraphs.Count
Set myRange = .Lists(j).ListParagraphs(i).Range
pos = InStrRev(myRange.Text, searchText, -1, _
vbTextCompare)
If pos > Len(myRange.Text) - 6 Then
myRange.Start = myRange.Start + pos - 1
myRange.End = myRange.Start + Len(searchText) - 4
myRange.Select
Selection.comments.Add _
Range:=Selection.Range, Text:="Please use noun
or plural form"
End If
Next
Next
End With
End Sub