Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-02-2023, 11:06 AM
RobiNew RobiNew is offline Insert a condition in Find and Replace Windows 10 Insert a condition in Find and Replace Office 2016
Competent Performer
Insert a condition in Find and Replace
 
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert a condition in Find and Replace Find & Replace to insert thousands separators jeffreybrown Word 3 10-19-2019 04:37 PM
Insert a condition in Find and Replace Find and replace condition norgro Word VBA 2 07-31-2015 06:38 AM
Insert a condition in Find and Replace Find and Replace - How to insert brackets around all numbers in a doc Natedogg Word 2 05-21-2015 07:16 AM
Insert a condition in Find and Replace Insert text at the end of a sentence Find/Replace AlmostFriday Word 6 06-17-2012 05:21 AM
Find & Replace Insert Issue mipacker Word 0 02-18-2009 08:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:37 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft