PPT2000: Help Example for Replace Method Is Incorrect (226601)
The information in this article applies to:
- Microsoft PowerPoint 2000
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.
RESOLUTIONMicrosoft 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
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbbug kbdtacode kbpending KB226601 |
---|
|