Find/Replace All Macro Help

jcolliu

New Member
Joined
Aug 27, 2014
Messages
19
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.

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!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,214,897
Messages
6,122,141
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top