msalman
04-08-2017, 04:43 AM
I was wondering if someone would be able to help me out here, how I could highlight duplicate paragraphs or text strings of specific bold fonts within a document. ( same code below but need add specific bold fonts):banghead: for more clearly:) just :thumb:crying: (Need highlight duplicate paragraphs or text strings of bold size only)
It would be great if I could highlight the duplicate Red and the first instance yellow or something along like the below code :) I'll apologise in advance for my limited knowledge of VB.
Sub VBAXTest()
Const NMin As Long = 5
Dim R As Range, W As Range
Dim C As Range, C2 As Range, N As Long
Set R = ActiveDocument.Content
For Each W In R.Words
If W.HighlightColorIndex = wdNoHighlight Then
N = NMin
Do
Set C = W.Duplicate
C.MoveEnd wdWord, N
If C.End = ActiveDocument.Range.End Then Exit Sub
Set C2 = ActiveDocument.Range(C.End, ActiveDocument.Range.End)
Select Case True
Case Len(C.Text) > 256, _
C.HighlightColorIndex = 9999999, _
C2.Find.Execute(FindText:=C.Text, Wrap:=wdFindStop) = False
If N > NMin Then DoHighLight C
Exit Do
Case Else
N = N + 1
End Select
Loop
End If
Next
End Sub
Sub DoHighLight(C As Range)
Dim C2 As Range
C.MoveEnd wdWord, -1
C.HighlightColorIndex = wdYellow
Set C2 = ActiveDocument.Range(C.End, ActiveDocument.Range.End)
While C2.Find.Execute(FindText:=C.Text, Wrap:=wdFindStop)
C2.HighlightColorIndex = wdRed
Wend
End Sub
It would be great if I could highlight the duplicate Red and the first instance yellow or something along like the below code :) I'll apologise in advance for my limited knowledge of VB.
Sub VBAXTest()
Const NMin As Long = 5
Dim R As Range, W As Range
Dim C As Range, C2 As Range, N As Long
Set R = ActiveDocument.Content
For Each W In R.Words
If W.HighlightColorIndex = wdNoHighlight Then
N = NMin
Do
Set C = W.Duplicate
C.MoveEnd wdWord, N
If C.End = ActiveDocument.Range.End Then Exit Sub
Set C2 = ActiveDocument.Range(C.End, ActiveDocument.Range.End)
Select Case True
Case Len(C.Text) > 256, _
C.HighlightColorIndex = 9999999, _
C2.Find.Execute(FindText:=C.Text, Wrap:=wdFindStop) = False
If N > NMin Then DoHighLight C
Exit Do
Case Else
N = N + 1
End Select
Loop
End If
Next
End Sub
Sub DoHighLight(C As Range)
Dim C2 As Range
C.MoveEnd wdWord, -1
C.HighlightColorIndex = wdYellow
Set C2 = ActiveDocument.Range(C.End, ActiveDocument.Range.End)
While C2.Find.Execute(FindText:=C.Text, Wrap:=wdFindStop)
C2.HighlightColorIndex = wdRed
Wend
End Sub