Consulting

Results 1 to 3 of 3

Thread: Looking for a macro to highlight missing full stops (periods)

  1. #1
    VBAX Newbie
    Joined
    Mar 2014
    Posts
    3
    Location

    Looking for a macro to highlight missing full stops (periods)

    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

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,334
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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.

    Quote Originally Posted by xld View Post
    You could use coinditional formatting with a formula of

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

    with a highlight colour.
    not in Word ...
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •