PC Review


Reply
Thread Tools Rate Thread

Replace text not working

 
 
=?Utf-8?B?V2VlZ2ll?=
Guest
Posts: n/a
 
      27th Mar 2006
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
 
Reply With Quote
 
 
 
 
Steve Rindsberg
Guest
Posts: n/a
 
      27th Mar 2006
In article <12636441-804C-4CE5-B960-(E-Mail Removed)>, 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
================================================


 
Reply With Quote
 
=?Utf-8?B?V2VlZ2ll?=
Guest
Posts: n/a
 
      28th Mar 2006
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


"Steve Rindsberg" wrote:

> In article <12636441-804C-4CE5-B960-(E-Mail Removed)>, 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
> ================================================
>
>
>

 
Reply With Quote
 
Steve Rindsberg
Guest
Posts: n/a
 
      28th Mar 2006
In article <BCB3284A-94C7-41B6-939A-(E-Mail Removed)>, 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-(E-Mail Removed)>, 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
================================================


 
Reply With Quote
 
=?Utf-8?B?V2VlZ2ll?=
Guest
Posts: n/a
 
      28th Mar 2006
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

"Steve Rindsberg" wrote:

> In article <BCB3284A-94C7-41B6-939A-(E-Mail Removed)>, 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-(E-Mail Removed)>, 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
> ================================================
>
>
>

 
Reply With Quote
 
Steve Rindsberg
Guest
Posts: n/a
 
      28th Mar 2006

In article <F48AABD3-4F8F-4245-BDA6-(E-Mail Removed)>, 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-(E-Mail Removed)>, 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-(E-Mail Removed)>, 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
================================================


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I replace color of selected text using the replace feature bb Microsoft Word Document Management 5 17th Jun 2008 06:19 AM
Can I replace a ' at the beginning of a text cell using Replace =?Utf-8?B?SGlsZGU=?= Microsoft Excel Misc 4 10th Sep 2007 07:22 PM
Re: I Need to replace many text area in a field with replace function. Smartin Microsoft Access Queries 8 18th Jan 2007 09:01 AM
Replace text with variable using VBA replace code? Mike Microsoft Excel Programming 2 9th Nov 2006 07:06 PM
Hi, can I replace plain text with bold text using Find/Replace or possibly with a macro? Derek Microsoft Excel New Users 9 4th Mar 2004 12:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:54 PM.