This procedure will loop through all the paragraphs in a div called "contentwide".
It will loop in reverse from the last to the first paragraph, since the paragraph I'm looking for is usually found near the bottom of my document.
If the first 6 letters of the paragraph are "Source" then I want to change the formatting of this paragraph. I have a css external style sheet which has the p.class and its attributes.
'Loop through paragraphs in reverse order
'from last to first.
For i = ActiveDocument.all.tags("div"). _
Item(intElementIndex). _
all.tags("p").Length - 1 To 0 Step -1
'set strHTML to the paragraph content.
strHTML = ActiveDocument.all.tags("div"). _
Item(intElementIndex). _
all.tags("p").Item(i).innerHTML
'Check if first 6 letters in paragraph
'are equal to "Source"
If Left(strHTML, 6) = "Source" Then
ActiveDocument.all.tags("div"). _
Item(intElementIndex). _
all.tags("p").Item(i).class = "source"
Exit For
End If
Next i
The start tag will appear as <p class="source"> after the procedure is run.