Replace text not working

W

Weegie

Hello there,

I've written a subroutine to search and replace text within all shapes in
the Slidemaster, TitleMaster, HandoutMaster and NoteMaster.

The subroutine works well when I try to find and replace one word. As soon
as I search for several words or load the search string via a config file,
nothing is replaced.

The subroutine is below and has been taken from previous posts.

Any ideas what I might be doing wrong ? Should I be doing something to the
search and replace strings before comparing them ?

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

Thanks
 
W

Weegie

Hi Steve,

I'm calling the subroutine using the code below, where oPresMaster is a
reference to the SlideMaster, TitleMaster etc., FindString is the string to
replace and Classification is the replacement string.

For Each oShp In oPresMaster.Shapes
Call ReplaceText(oShp, FindString, Classification)
Next oShp

When FindString is "Commercial" the replacement works fine. When it is
"Commercial in Confidence", nothing happens.

Any ideas ?

Thanks

Weegie
 
W

Weegie

Shooting it works for me !

Ended up doing something similar to what you suggested by getting the text
from the shape, replacing the string using the VB.net replace function and
then re-assigning the replacment text to the shape.

The code is below for reference.

Thanks for your help Steve.

If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
strTest = oShp.TextFrame.TextRange.Text
strTest = Replace(strTest, FindString, ReplaceString)
oShp.TextFrame.TextRange.Text = strTest
End If
End If
 

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