Hello, this is for a macro in powerpoint 2010 to find a list of 30+ words found formatted in Queen's English and convert them to American English (analyze -> analyse). I'm hoping to have the macro jump to and select the word it's trying to replace, and prompt the user with yes/no if they want it to be replaced. I've gotten this to work with this code only intermittently, most of the time it throws a runtime error.
Most of this code was copy/pasted with me tweaking it here and there so I wouldn't be surprised if it's messy or there's a glaring issue with it. On another note, I'd like to be able to match the case of the found word and replace it appropriately (analyse -> analyze, Analyse -> Analyze). Thanks for the insight!
Code:
Sub us_qe()
Dim fnd As Variant
Dim rplc As Variant
Dim FindArray As Variant
Dim ReplaceArray As Variant
Dim TxtRng As TextRange
Dim TmpRng As TextRange
Dim sld As Slide
Dim shp As Shape
'Find/Replace Variables
FindArray = Array("analyze", "annualize", "nationalize")
ReplaceArray = Array("analyse", "annualise", "nationalise")
'Loop Through Each Slide
For Each sld In ActivePresentation.Slides
ActiveWindow.View.GotoSlide sld.SlideIndex
For y = LBound(FindArray) To UBound(FindArray)
For Each shp In sld.Shapes
fnd = FindArray(y)
rplc = ReplaceArray(y)
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
Set TxtRng = shp.TextFrame.TextRange.Find(fnd, 0, False, True)
TxtRng.Select
If MsgBox("Replace " & fnd & " with " & rplc & "?", vbYesNo) = vbYes Then Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _
ReplaceWhat:=rplc, WholeWords:=False, MatchCase:=False)
End If
End If
'Replace Other Instances (if necessary)
Do While Not TmpRng Is Nothing
Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _
ReplaceWhat:=rplc, WholeWords:=False, MatchCase:=False)
Loop
Next shp
Next y
Next sld
MsgBox "QE replaced with US"
End Sub
Most of this code was copy/pasted with me tweaking it here and there so I wouldn't be surprised if it's messy or there's a glaring issue with it. On another note, I'd like to be able to match the case of the found word and replace it appropriately (analyse -> analyze, Analyse -> Analyze). Thanks for the insight!