View Single Post
 
Old 12-02-2023, 11:06 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 208
RobiNew is on a distinguished road
Default Insert a condition in Find and Replace

I'm trying to insert a condition in the code here below. The style should be replaced only if the number of italicized characters is less than 30. Can someone help? Thanks!
Code:
Sub Italic()
With ActiveDocument
If Not .Styles("myItalic") Is Nothing Then
  For iType = 1 To 2
    Set aRng = ActiveDocument.StoryRanges(iType)
    With aRng.Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = ""
      .Replacement.Text = ""
      .Font.Italic = True
If aRng.Characters.Range.Count < 30 Then _
.Replacement.Style = ActiveDocument.Styles("myItalic")
      .Forward = True
      .Wrap = wdFindContinue
      .Format = True
      .MatchCase = False
      .Execute Replace:=wdReplaceAll
    End With
  Next iType
End If
End With
End Sub
Reply With Quote