View Single Post
 
Old 12-02-2023, 03:18 PM
vivka vivka is offline Windows 7 64bit Office 2016
Expert
 
Join Date: Jul 2023
Posts: 302
vivka is on a distinguished road
Default

Hi, RobiNew! The following code finds italicized strings in each storyrange and, if the italicized string is less-than-30-chars-long, the whole storyrange gets styled as needed. I tested the code only once, so it may have some problems.
Code:
Sub Italicize_If()

Dim aRng As range
  For iType = 1 To 2
    Set aRng = ActiveDocument.StoryRanges(iType)
    With aRng.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .text = ""
        .Replacement.text = ""
        .Font.Italic = True
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        Do
        If .Execute And aRng.Characters.count < 30 Then
            aRng.Select
            ActiveDocument.StoryRanges(iType).Style = "myItalic"
            GoTo lbl_next
        End If
        aRng.Collapse wdCollapseEnd
        Loop
    End With
lbl_next:
  Next iType
lbl_exit:
Set aRng = Nothing
End Sub
Reply With Quote