PPT Replace method

J

John Svendsen

Hi All,

I have a macro that substitutes one string for another in PPT - however, if
there are 2 or more occurences of the same string in a same shape, only the
1st occurence is replaced, not the others.

Below is the piece of my replace code:

=========================================
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Replace FindWhat:=sFirst, _
Replace:=sLast, MatchCase:=True, WholeWords:=True
End If
End If
=========================================

(OBS: word replace has the wdFindContinue in the Wrap property - I do not
see this in PPT, does it exist?)

Thanks in advance for any ideas.

Regards, JS
 
J

John Svendsen

Hi Steve,

Thanks again for your reply.

Question: this new method complained about "MatchCase:=True,
WholeWords:=True", and this is something I need to have.

Is there a way around this?

Againg, Tks, JS
 
J

John Svendsen

Hey Steve,

Cool!!!

:)

Tks so much!!

JS

Steve Rindsberg said:
Oops. Misunderstood (or at least misanswered) your question. ;-)

OK, play with this a bit:

Sub TryThis()

Dim shp As Shape
Dim sFind As String
Dim sReplaceWith As String
Dim x As Long

Set shp = ActiveWindow.Selection.ShapeRange(1)
sFind = "text to find"
sReplaceWith = "text to replace it with"
x = 1

If shp.HasTextFrame Then
If shp.TextFrame.HasText Then

While x < Len(shp.TextFrame.TextRange)
' find the next occurrence of the Find string:
x = InStr(x, shp.TextFrame.TextRange.Text, sFind, vbBinaryCompare)
If x > 0 Then ' found one, try the replace on it
' notice that it's supposed to be ReplaceWhat:=
' rather than Replace:=
shp.TextFrame.TextRange.Replace FindWhat:=sFind, _
ReplaceWhat:=sReplaceWith, MatchCase:=True, WholeWords:=True
Else ' none found, we're done, leave.
Exit Sub
End If
' increment x so we don't keep finding the same string over and over
x = x + 1
Wend

End If
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top