Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-10-2021, 03:52 AM
Bikram Bikram is offline Find and Replace Windows 10 Find and Replace Office 2007
Advanced Beginner
Find and Replace
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Post Find and Replace

Greeting to all, I wrote the following code to find and replace multiple fonts but it is not working


Code:
Sub Macro39()

 Dim i As Integer
 Dim fta()
 
    fta = Array("Book Antiqua", "Arial Narrow","Arial")
        For i = 0 To UBound(fta)
            With Selection.find
                .ClearFormatting
                .Replacement.ClearFormatting
                .Font.Bold = True
                .Font.Name = fta(i)
            End With
            With Selection.find
                .Text = ""
                .Replacement.Text = ""
                .Forward = True
                .Wrap = wdFindStop
                .Format = True
                .MatchCase = False
                .MatchWholeWord = False
                .MatchWildcards = False
                .MatchSoundsLike = False
                .MatchAllWordForms = False
            End With
                Do While Selection.find.Execute = True
                    Select Case Selection.Range.Style
                    Case "tt"
                        Selection.Range.Select
                            With Selection
                                .Font.Name = "Lato Heavy"
                                .Font.Size = 7.5
                                .Font.Bold = False
                                .MoveRight unit:=wdWord, Count:=1
                            End With
                    Case "aq", "b"
                        With Selection
                            .Font.Name = "Arial"
                            .Font.Size = 7.5
                            .Font.Bold = False
                            .MoveRight unit:=wdWord, Count:=1
                      End With
                    End Select
                Loop
        Next
End Sub
It works but only for the first item in the array. Can someone point out why is it not working as expected? Thanks in advance.
Reply With Quote
  #2  
Old 12-12-2021, 03:34 AM
Guessed's Avatar
Guessed Guessed is offline Find and Replace Windows 10 Find and Replace Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
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

I would start by looking at the .Wrap = wdFindStop
This would be telling the code to stop when it gets to the end of the document. At the end of the first pass, your selection object would be near the end so if there are no second pass entries between it and the end of the document then nothing will be found.

You could change it to wdFindContinue or reset the selection to the top of the document at the start of each loop.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 12-12-2021, 05:05 AM
Bikram Bikram is offline Find and Replace Windows 10 Find and Replace Office 2007
Advanced Beginner
Find and Replace
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default

Thank you Andrew, it worked.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you use the find and replace tool to find dates and times in Excel 2013? Jules90 Excel 3 04-14-2020 07:40 PM
In Find and Replace, can Word stop after each Replace? wardw Word 1 06-08-2017 02:47 PM
Find and Replace Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
Find and Replace Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Find and Replace Help with find and replace or query and replace shabbaranks Excel 4 03-19-2011 08:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:22 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