Possible problem with TextRange.Replace Method in Powerpoint 2007 ???

  • Thread starter Thread starter John Svendsen
  • Start date Start date
J

John Svendsen

Hi All:
Could I have done something wrong, or is this behavior abnormal?
- open a new presentation in Powerpoint 2007 (not earlier versions),
- add a Text Box and write in the text below:
"this test was a blind with 100 interviews"
- run the code below (from Powerpoint's VBA Help):
It keeps on replacing "ad infinitum" when it shouldn't...
TIA, JS

Sub ReplaceText_MSO()
Dim oSld As Slide
Dim oShp As Shape
Dim oTxtRng As TextRange
Dim oTmpRng As TextRange
Set oSld = Application.ActivePresentation.Slides(1)
For Each oShp In oSld.Shapes
Set oTxtRng = oShp.TextFrame.TextRange
Set oTmpRng = oTxtRng.Replace(FindWhat:="blind", Replacewhat:="blind
test", WholeWords:=True)
Do While Not oTmpRng Is Nothing
Set oTxtRng = oTxtRng.Characters(oTmpRng.Start + oTmpRng.Length,
oTxtRng.Length)
Set oTmpRng = oTxtRng.Replace(FindWhat:="blind",
Replacewhat:="blind test", WholeWords:=True)
Loop
Next oShp
End Sub
 
Hi All:
Could I have done something wrong, or is this behavior abnormal?

A *lot* of VBA behavior in PPT 2007 is abnormal.
Your code's ok.

You may want to try stepping through it to see where it's failing.
 
Works fine here. It does error (for me) with Shyam's suggested mod for 2007
Do While oTmpRng.Text <> ""

I think maybe this was to correct a bug in the beta but I'm not sure.
 
Back
Top