D
david.f.jenkins
I'm hoping I can get a) an explanation for the results I'm seeing, and
b) some guidance on how to achieve the results I want.
I've written the following macro:
Option Explicit
Sub Replace_Test()
Dim NewRange, TempRange As TextRange
Dim myDocument
Set myDocument = ActivePresentation.Slides(1)
With myDocument.Shapes.AddShape(msoShapeRectangle, 0, 0, 250,
140).TextFrame
.TextRange.Text = "abcd efgh"
.MarginLeft = 10
.MarginRight = 10
Set NewRange = .TextRange.Characters(.TextRange.Start, 4)
Set TempRange = NewRange.replace(FindWhat:="abcd", _
Replacewhat:="wxyz", _
WholeWords:=msoFalse, _
MatchCase:=msoFalse)
End With
End Sub
When debugging, NewRange.Text contains "abcd" before the replace, but
"wxyz efgh" after the replace; TempRange shows the expected "wxyz"
after the replace. Why has the NewRange text been expanded to include
the " efgh"? What I'm expecting (and what I need) is for NewRange to
contain "wxyz" after the replace.
I imagine that I'm exhibiting my ignorance in the proper use of
references, objects, etc., but I'm out of ideas as to what to try next.
Hope you all can clear this up for me - it's caused untold grief over
the last day or so!
b) some guidance on how to achieve the results I want.
I've written the following macro:
Option Explicit
Sub Replace_Test()
Dim NewRange, TempRange As TextRange
Dim myDocument
Set myDocument = ActivePresentation.Slides(1)
With myDocument.Shapes.AddShape(msoShapeRectangle, 0, 0, 250,
140).TextFrame
.TextRange.Text = "abcd efgh"
.MarginLeft = 10
.MarginRight = 10
Set NewRange = .TextRange.Characters(.TextRange.Start, 4)
Set TempRange = NewRange.replace(FindWhat:="abcd", _
Replacewhat:="wxyz", _
WholeWords:=msoFalse, _
MatchCase:=msoFalse)
End With
End Sub
When debugging, NewRange.Text contains "abcd" before the replace, but
"wxyz efgh" after the replace; TempRange shows the expected "wxyz"
after the replace. Why has the NewRange text been expanded to include
the " efgh"? What I'm expecting (and what I need) is for NewRange to
contain "wxyz" after the replace.
I imagine that I'm exhibiting my ignorance in the proper use of
references, objects, etc., but I'm out of ideas as to what to try next.
Hope you all can clear this up for me - it's caused untold grief over
the last day or so!