Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #12  
Old 12-03-2023, 03:35 PM
Guessed's Avatar
Guessed Guessed is offline Insert a condition in Find and Replace Windows 10 Insert a condition in Find and Replace Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,177
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

This variation on Vivka's code avoids the selection object and hence it runs a lot faster.
Code:
Sub Italicize_If2()
  Dim aRng As Range, iType As Integer
  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 = wdFindStop
        .Format = True
        .MatchCase = False
        Do While .Execute
          If aRng.Characters.Count < 30 Then aRng.Style = "myItalic"
          aRng.Collapse wdCollapseEnd
        Loop
    End With
  Next iType
lbl_exit:
  Set aRng = Nothing
  Exit Sub
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
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 05:47 AM.


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