PDA

View Full Version : Looking for a macro to highlight missing full stops (periods)



ORANGESH
03-21-2014, 07:33 AM
Hi folks,

I was reading this previous post (I'm not allowed to hyperlink yet) which had some excellent code to automatically add full stops where they are missing from the end of paragraphs.

I'm wondering if a similar code could be used to find these instances, and simply highlight the last character so that I could search by highlight, correct each instance where necessary, then remove all the highlights manually.

This would make it easier for me because there are many examples in my documents where we don't need full stops and it would be better to use my own judgement.

Thanks
George

gmaxey
03-21-2014, 11:18 AM
Sub Demo()
Application.ScreenUpdating = False
Dim Para As Paragraph
On Error Resume Next
For Each Para In ActiveDocument.Paragraphs
With Para.Range
If .Characters.Last.Previous.InRange(ActiveDocument.TablesOfContents(1).Range) = False Then
If Left(.Style.NameLocal, 7) <> "Heading" Then
If Len(.Text) > 2 Then
If Not .Characters.Last.Previous Like "[.!?:;]" Then
.Characters.Last.Previous.HighlightColorIndex = wdBrightGreen
End If
End If
End If
End If
End With
Next
Application.ScreenUpdating = True
End Sub

macropod
03-21-2014, 03:54 PM
Generally speaking, you don't need a macro for this, a simple wildcard Find/Replace will do, where:
Find = [!.\;\?\;\-\!]^13
Replace = ^&
and replacement highlighting is specified.

Note that the Find expression avoids highlighting sentences that end in other punctuation marks also. The only place it won't work is for a table cell where the text is terminated by an end-of-cell marker. Also, unlike Greg's macro, paragraphs using heading Styles aren't treated any differently.


You could use coinditional formatting with a formula of

=RIGHT(A2,1)<>"."

with a highlight colour.
not in Word ...