Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-19-2021, 01:31 AM
Bikram Bikram is offline multiple replacing Windows 10 multiple replacing Office 2007
Advanced Beginner
multiple replacing
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default multiple replacing

I have 2 sub procedures to find multiple items and replace them in multiple files at once through vba my first procedure works fine but the second procedure is not working and I don't know why, can someone point out why the following code is not working? Thanks in advance.
It is the second procedure which is not working

Sub findM()
Dim strfind()
Dim strreplace()
Dim i As Integer

With Selection.Range
.find.ClearFormatting
.find.Replacement.ClearFormatting
End With
strfind = Array("cË", "km")
strreplace = Array("cª\u", "º")
For i = 0 To UBound(strfind)
With Selection.Range.find


.Text = strfind(i)
.Format = True
.Forward = True
.MatchAlefHamza = False
.MatchWildcards = False
.MatchWholeWord = False
.Replacement.Text = strreplace(i)
End With
Selection.find.Execute Replace:=wdReplaceAll
Next

End Sub
Reply With Quote
  #2  
Old 11-19-2021, 04:44 AM
gmayor's Avatar
gmayor gmayor is offline multiple replacing Windows 10 multiple replacing Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You haven't selected anything, so a search in Selection.Range will not find anything.
Try the following:
Code:
Sub findM()
Dim strfind() As Variant
Dim strreplace() As Variant
Dim i As Integer
    strfind = Array("cE", "km")
    strreplace = Array("c?\u", "?")
    For i = 0 To UBound(strfind)
        Selection.HomeKey wdStory
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = strfind(i)
            .Format = True
            .Forward = True
            .MatchAlefHamza = False
            .MatchWildcards = False
            .MatchCase = True
            .MatchWholeWord = False
            .Replacement.Text = strreplace(i)
            .Execute Replace:=wdReplaceAll
        End With
    Next i
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-19-2021, 05:09 AM
Bikram Bikram is offline multiple replacing Windows 10 multiple replacing Office 2007
Advanced Beginner
multiple replacing
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default

Thank you, sir. It worked.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple replacing replacing multiple ranges in excel with tables in word from top to bottom modiria50989 Word VBA 5 09-13-2017 04:01 PM
multiple replacing Replacing Timestamps Madcat Word 1 08-23-2014 09:09 PM
multiple replacing Replacing multiple words at once in excel document Legaly Excel 2 05-23-2014 08:30 AM
Replacing texts aslamyahya Excel Programming 1 02-27-2013 10:38 PM
Replacing a Resource in Multiple Tasks Simultaneously taffytron Project 3 12-31-2012 02:21 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:28 AM.


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