View Single Post
 
Old 03-29-2023, 01:33 PM
gmaxey gmaxey is offline Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,431
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You are welcome. Here is a little more polished version:
Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oWord As Range
Dim oRngFlag As Range
Dim lngCount As Long
Dim lngLimit As Long
  lngLimit = InputBox("Enter the long sentence word count", "LIMIT", "30")
  Set oWord = ActiveDocument.Words(1)
  Set oRngFlag = oWord.Duplicate
  Do
    Debug.Print oWord.Characters(1)
    Select Case True
      Case oWord.Characters(1).Text Like "[A-Za-z]"
        lngCount = lngCount + 1
      Case oWord.Characters(1).Text Like "[.,:;\!\?]"
        lngCount = 0
        oWord.Select
        oRngFlag.Start = oWord.End
    End Select
    oWord.Move wdWord, 1
    oRngFlag.End = oWord.End
    If lngCount = lngLimit Then
      Do While Not oRngFlag.Characters.First Like "[A-Za-z]"
        oRngFlag.MoveStart wdCharacter, 1
      Loop
      Do
        oRngFlag.MoveEnd wdCharacter, 1
      Loop Until oRngFlag.Characters.Last Like "[.,:;\!\?" & Chr(13) & "]"
      oRngFlag.HighlightColorIndex = wdBrightGreen
      oRngFlag.Collapse wdCollapseEnd
      lngCount = 0
    End If
  Loop Until oWord.End = ActiveDocument.Range.End - 1
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote