Microsoft KB Archive/226601

= PPT2000: Help Example for Replace Method Is Incorrect =

Article ID: 226601

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft PowerPoint 2000 Standard Edition

-



This article was previously published under Q226601



SYMPTOMS
If you implement the code example from the Replace Method topic in the Microsoft Visual Basic Help, you will find that it will only replaces one occurrence of the search string.

Below is the incorrect code sample from the Help file example: For Each sld In Application.ActivePresentation.Slides For Each shp In sld.Shapes shp.TextFrame.TextRange.Replace FindWhat:="CompanyX", _ Replacewhat:="CompanyY", WholeWords:=True Next shp Next sld



CAUSE
The code, given in the help article on the Replace Method in the Microsoft Visual Basic Help, only replaces the first occurrence of the search string being looked for. It does not continue searching the text frame until it can no longer find the search string.



RESOLUTION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following code sample correctly implements the Replace Method example for PowerPoint 2000: Sub test Dim oSld As Slide Dim oShp As Shape Dim oTxtRng As TextRange Dim oTmpRng As TextRange Set oSld = Application.ActivePresentation.Slides(1) For Each oShp In oSld.Shapes Set oTxtRng = oShp.TextFrame.TextRange Set oTmpRng = oTxtRng.Replace(FindWhat:="like", _        Replacewhat:="NOT LIKE", WholeWords:=True) Do While Not oTmpRng Is Nothing Set oTxtRng = oTxtRng.Characters(oTmpRng.Start + oTmpRng.Length, _            oTxtRng.Length) Set oTmpRng = oTxtRng.Replace(FindWhat:="like", _           Replacewhat:="NOT LIKE", WholeWords:=True) Loop Next oShp End Sub

Additional query words: PPT2K PPT2000 PPT POWERPNT 2000 PPT9 9.0 vba

Keywords: kbbug kbdtacode kbpending KB226601

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.