PDA

View Full Version : Find and Replace for all instances of "Find" list



Raybob
02-18-2022, 10:11 AM
I am trying to run a find/replace using arrays, and it works, but only for the first instances on each slide. I have a slide title with duplicate words, but only the first is replaced, so I'm hoping for some help to get both words replaced.
Thanks!


'LOOP THROUGH EACH SLIDE
For Each sld In objPPT.ActivePresentation.Slides
For Y = LBound(FindArray1) To UBound(FindArray1)
fnd = FindArray1(Y)
rplc = ReplaceArray1(Y)
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
Set TxtRng = shp.TextFrame.TextRange.Find(fnd, 0, True, WholeWords:=msoTrue)
If Not TxtRng Is Nothing Then
Do
Set tmprng = TxtRng.Replace(FindWhat:=fnd, ReplaceWhat:=rplc, WholeWords:=True, MatchCase:=True)
Loop While Not tmprng Is Nothing
End If
End If
End If
Next shp
Next Y
Next sld

John Wilson
02-19-2022, 06:56 AM
Replace DOES stop at the first instance unless you tell it to continue


'first instance
Set tmpRng = txtRng.Replace(FindWhat:=fnd, ReplaceWhat:=rplc, WholeWords:=True, MatchCase:=True)
Do
'others
Set tmpRng = txtRng.Replace(FindWhat:=fnd, ReplaceWhat:=rplc, After:=tmpRng.Start + tmpRng.Length, WholeWords:=True, MatchCase:=True)
Loop While Not tmpRng Is Nothing

RogerEye1253
06-07-2022, 08:30 PM
Replace DOES stop at the first instance unless you tell it to continue


'first instance
Set tmpRngSoul Knight Mod APK (https://megamodapk.com/soul-knight-mod-apk/) = txtRng.Replace(FindWhat:=fnd, ReplaceWhat:=rplc, WholeWords:=True, MatchCase:=True)
Do
'others
Set tmpRng = txtRng.Replace(FindWhat:=fnd, ReplaceWhat:=rplc, After:=tmpRng.Start + tmpRng.Length, WholeWords:=True, MatchCase:=True)
Loop While Not tmpRng Is Nothing

Thank you so much, you helped me too.

Andrew125
06-08-2022, 09:08 AM
Replace DOES stop at the first instance unless you tell it to continue


'first instance
Set tmpRng = txtRng.Replace(FindWhat:=fnd, ReplaceWhat:=rplc, WholeWords:=True, MatchCase:=True)
Do
'others
Set tmpRng = txtRng. (https://gbwamod.com/download-yowhatsapp-apk/)Replace(FindWhat:=fnd, ReplaceWhat:=rplc, After:=tmpRng.Start + tmpRng.Length, WholeWords:=True, MatchCase:=True)
Loop While Not tmpRng Is Nothing


Very helpful, indeed.

goreeans
03-22-2024, 11:48 PM
I am trying to run a find/replace using arrays, and it works, but only for the first instances on each slide. I have a slide title with duplicate words, but only the first is replaced, so I'm hoping for some help to get both words replaced.
Thanks!


'LOOP THROUGH EACH SLIDE
For Each sld In objPPT.ActivePresentation.Slides
For Y = LBound(FindArray1) To UBound(FindArray1)
fnd = FindArray1(Y)
rplc = ReplaceArray1(Y)
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
Set TxtRng = shp.TextFrame.TextRange.Find(fnd, 0, True, WholeWords:=msoTrue)
If Not TxtRng Is Nothing Then
Do
Set tmprng = TxtRng.Replace(FindWhat:=fnd, ReplaceWhat:=rplc, WholeWords:=True, MatchCase:=True)
Loop While Not tmprng Is Nothing
End If
End If
End If
Next shp
Next Y
Next sld


Thanks for sharing it with us!