Re: Replace text not working




In article <F48AABD3-4F8F-4245-BDA6-791B1EEDA89C@xxxxxxxxxxxxx>, Weegie wrote:
Shooting it works for me !

Great!

Not criticizing or complaining but just curious: why assign the TextRange.Text to a
variable, process, then reassign back to the TextRange.Text?

It's certainly easier to read that way. <g>



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

"Steve Rindsberg" wrote:

In article <BCB3284A-94C7-41B6-939A-53C6B9E22048@xxxxxxxxxxxxx>, Weegie wrote:
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 ?

Shoot it? I've never had much luck with this function.

Does this get it for you?

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



Thanks

Weegie

"Steve Rindsberg" wrote:

In article <12636441-804C-4CE5-B960-7D7466C62308@xxxxxxxxxxxxx>, Weegie wrote:
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.

How are you trying to search for several words? The routine will only
search/replace one string at a time. You'd need to invoke it once for each
string you need to replace.

Hint: you've posted the part of the code that doesn't change; the problem is
in the part that does change. ;-)

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


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================





-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================





-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================


.



Relevant Pages


Loading