I try to detect simple, compound, complex and complex-compound using Word VBA and color the sentence using occurrence of punctuation pattern.
Having challenge detecting the start of the sentence in .Text = ";*." and find complex-compound overrides complex function.
Expected output
Tom reads newspapers.
Tom reads novels and newspapers.
Tom reads and enjoys novels.
Tom and Harry read novels.
Tom and Harry read and enjoy novels and newspapers.
Tom reads novels, but Jack reads comics.
Tom reads novels; however, Jack reads comics.
Tom reads novels; his friend reads comics.
Although Tom reads novels, Jack reads comics.
Jack reads comics although Tom reads novels.
Jack Smith, who reads comics, rarely reads novels.
People who read comics rarely read novels.
While Tom reads novels, Jack reads comics, but Sam reads only magazines.
Tom reads novels, but Jack reads comics because books are too difficult.
Jack, who reads comics, rarely reads novels; however, Tom enjoys novels.
People who read comics rarely read novels; they often find books difficult.
Sub clause()
StatusBar = "Phrase highlighting."
'A basic Word macro coded by Greg Maxey
Dim oPar As Paragraph
Dim oRng, oRng1 As Range
Set oPar = ActiveDocument.Paragraphs(1)
Do
If InStr(1, oPar.Range.Text, ",") > 0 Then
Set oRng = oPar.Range
With oRng
.Collapse 1
.MoveEndUntil "."
.Font.Color = wdColorRed
End With
End If
Set oPar = oPar.Next
Loop Until oPar Is Nothing
Application.ScreenUpdating = False
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = ";*."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
.Font.Color = wdColorBlue
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
StatusBar = ""
End Sub
Current output
Untitled.jpg
How to go about with this? Is my approach correct?
Future scope - Planning to put conjunction and conjugate adverb in an array and color sentences based on its occurrence. Is there a link or way where i can check how to color a sentence if a particular word occurs within the sentence.