View Single Post
 
Old 02-12-2024, 07:14 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Give this a try
Code:
Sub AddPuncDemo2()
  Dim Para As Paragraph, oRng As Range, sLastWord As String, sFirstChar As String
  'Application.ScreenUpdating = False
  For Each Para In ActiveDocument.Paragraphs
    With Para.Range
      If .Information(wdInFieldResult) Or .Information(wdWithInTable) Or .Font.AllCaps Or .Font.Bold Or Len(.Text) < 3 Then
        GoTo NextFor
      Else
        Do While .Characters.Last.Previous = " "
          .Characters.Last.Previous.Delete
        Loop
        sFirstChar = .Characters(1)
        sLastWord = .Words.Last.Previous.Words(1)
        Debug.Print sFirstChar, sLastWord
        If Not sLastWord Like "*[.!?:;]" Then 'If para ends with any of these characters do nothing
          Select Case sLastWord
            Case "and", "but", "or", "then", "plus", "minus", "less", "nor"
              'do nothing
            Case Else
              If sFirstChar = UCase(sFirstChar) Then
                .Characters.Last.InsertBefore "." 'Insert period if para starts Uppercase
              Else
                .Characters.Last.InsertBefore ";" 'Insert semi colon if para starts lowercase
              End If
          End Select
        End If
      End If
    End With
NextFor:
  Next
  'Application.ScreenUpdating = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote