C
Christopher King
Say you've got three bullets with identical text in a shape on a slide. You
select the middle one, and use
activewindow.selection.textrange.find
to find, then replace text. If the code in the help file is used, text will
also be replaced in the first and last bulleted paragraphs.
Here is a work-around. To illustrate, place HCl -> H2O in a slide, where it
says "Click to add text". Place it in there at least three times. Select
the middle paragraph (the middle bulleted item, if the bullets are showing).
Here's the code:
Sub play()
' Replace "->" with a prettier arrow
Dim trPartial As TextRange
Dim trFoundText As TextRange
Dim lAfter As Long
Set trPartial = ActiveWindow.Selection.TextRange
Set trFoundText = trPartial.Find(FindWhat:="->", after:=trPartial.Start -
1)
Do While Not (trFoundText = "")
With trFoundText
' Make sure the found text isn't after the end of the selection
If .Start < trPartial.Start - 1 + trPartial.Length Then
.InsertSymbol FontName:="Symbol", charnumber:=174, unicode:=False
lAfter = .Start + .Length
Else
Exit Do
End If
End With
Set trFoundText = trPartial.Find(FindWhat:="->", after:=lAfter)
Loop
End Sub
Running that should replace the -> with a prettier arrow, but only in the
selected paragraph. What's new is that a value for "after" must be
specified, or else Find will start at the beginning of the text in the shape,
rather than at the beginning of the TextRange it was given. Likewise, it
will keep going to the end of the shape's TextRange, rather than the end of
the selection.
A nice feature of Find is that it can find unicode characters. If you type
--> in a shape, PowerPoint will automatically convert it to an (ugly) arrow,
provided autocorrect is turned on. You can select just that arrow, then in
the immediate window type
? ascw(ActiveWindow.Selection.TextRange)
-3872 is displayed.
Include the following in BOTH Find commands:
FindWhat:=ChrW(-3872)
Run the code and it will find and replace the ugly arrows with prettier ones.
Hope this saves somebody some time.
Chris
select the middle one, and use
activewindow.selection.textrange.find
to find, then replace text. If the code in the help file is used, text will
also be replaced in the first and last bulleted paragraphs.
Here is a work-around. To illustrate, place HCl -> H2O in a slide, where it
says "Click to add text". Place it in there at least three times. Select
the middle paragraph (the middle bulleted item, if the bullets are showing).
Here's the code:
Sub play()
' Replace "->" with a prettier arrow
Dim trPartial As TextRange
Dim trFoundText As TextRange
Dim lAfter As Long
Set trPartial = ActiveWindow.Selection.TextRange
Set trFoundText = trPartial.Find(FindWhat:="->", after:=trPartial.Start -
1)
Do While Not (trFoundText = "")
With trFoundText
' Make sure the found text isn't after the end of the selection
If .Start < trPartial.Start - 1 + trPartial.Length Then
.InsertSymbol FontName:="Symbol", charnumber:=174, unicode:=False
lAfter = .Start + .Length
Else
Exit Do
End If
End With
Set trFoundText = trPartial.Find(FindWhat:="->", after:=lAfter)
Loop
End Sub
Running that should replace the -> with a prettier arrow, but only in the
selected paragraph. What's new is that a value for "after" must be
specified, or else Find will start at the beginning of the text in the shape,
rather than at the beginning of the TextRange it was given. Likewise, it
will keep going to the end of the shape's TextRange, rather than the end of
the selection.
A nice feature of Find is that it can find unicode characters. If you type
--> in a shape, PowerPoint will automatically convert it to an (ugly) arrow,
provided autocorrect is turned on. You can select just that arrow, then in
the immediate window type
? ascw(ActiveWindow.Selection.TextRange)
-3872 is displayed.
Include the following in BOTH Find commands:
FindWhat:=ChrW(-3872)
Run the code and it will find and replace the ugly arrows with prettier ones.
Hope this saves somebody some time.
Chris