Find and replace a set of strings in Powerpoint

  • Thread starter Thread starter DollyJolly
  • Start date Start date
D

DollyJolly

Hi, I need to find a set of words in powerpoint and update them with another
set of words. Though we have the "Find and Replace" option in powerpoint,
changing numerous words is quite hectic. I saw the following code in the
website pptfaqs.com.

-----
Sub TheCatInTheHat()
Dim oTextRange As TextRange
Dim OriginalString As String
Dim NewString As String
Dim FindThis As String ' what string are we looking for?
Dim SubstituteThat As String ' what do we replace it with

FindThis = "XXXXXX"
SubstituteThat = "yada yada yada"

Set oTextRange = ActiveWindow.Selection.ShapeRange.TextFrame.TextRange
OriginalString = oTextRange.Text


' Is the target string part of the text? If not, bug out.
If InStr(OriginalString, FindThis) = 0 Then
Exit Sub
End If

' Get the portion of the string up to but not including where FindThis starts
NewString = Mid$(OriginalString, 1, InStr(OriginalString, FindThis) - 1)

' Add the substitute string
NewString = NewString & SubstituteThat

' Add the portion of the original string after but not including FindThis
NewString = NewString & Mid$(OriginalString, InStr(OriginalString, FindThis)
+ Len(FindThis))

' Uncomment this, comment out the next if you want to see the result w/o
changing the original
'MsgBox NewString

oTextRange.Text = NewString
End Sub
-------------------
I'm not familiar with VB code. I face the following problems when I run this
in the VB editor of Powerpoint 2003:
1) This code requires the required text box to be selected. Unless we select
a text box, the matching text inside it will not be changed.
2) This works only for changing one word. The macro code needs to be updated
so that it works for a set of words.

Any help in this regard would be highly appreciated.
 
Hi

Can you explain what you mean by a "set of words"?

Is it :

Replace "The cat sat on the mat" by "The dog ate a bone"

OR

Replace "This" with "That" AND "In" with "Out" AND "Snow" with "Rain" etc
 
Back
Top