Re: Using VBA to replace text



Here's the code I'm using. The line break is still not getting into
the find and replace values. At least when I copy their values to the
notrepad along with the actual TextRange I get line breaks in the
TextRange and not in the find and replace strings. Pretty weird. I'm
running PP 2002 SP3. The code was pulled directly from the VBA help
file for the Replace Method.

I have to use the find value because I have multiple textboxes on the
masters and can't depend on knowing the physical number of the
textbox..

Sub Change_Legal_Line()

Dim oShp As Shape
Dim FindWhat As String
Dim ReplaceWith As String

FindWhat = "EDS is a registered mark and the EDS logo is a trademark
of Electronic Data Systems Corporation." & Chr(13) & "EDS is an equal
opportunity employer and values the diversity of its people. " &
Chr(13)
& "(c) 2004 Electronic Data Systems Corporation. All rights reserved."

ReplaceWith = "EDS and the EDS logo are registered trademarks of
Electronic Data Systems Corporation." & Chr(13) & "EDS is an equal
opportunity employer and values the diversity of its people." &
Chr(13)
& "(c) 2005 Electronic Data Systems Corporation. All rights reserved."

For Each oShp In ActivePresentation.TitleMaster.Shapes
Call ReplaceText(oShp, FindWhat, ReplaceWith)
Next oShp

End Sub


Sub ReplaceText(oShp As Object, FindString As String, ReplaceString As
String)

Dim oTxtRng As TextRange
Dim oTmpRng As TextRange
Dim strTest As String
On Error Resume Next

If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
Set oTxtRng = oShp.TextFrame.TextRange
Set oTmpRng = oTxtRng.Replace(FindWhat:=FindString, _
Replacewhat:=ReplaceString, WholeWords:=True)
Do While Not oTmpRng Is Nothing
Set oTmpRng = oTxtRng.Replace(FindWhat:=FindString, _
Replacewhat:=ReplaceString, After:=oTmpRng.Start + _
oTmpRng.Length,WholeWords:=True)
Loop
End If
End If
End Sub

Thank you both for your help.

Take care,
Jeff
.



Relevant Pages