Reputation: 1
The text in the shape "TextBox 1" is "Work stack.<8Spaces>###Resource: Name1". I want to delete "###" from the above text using ppt vba. The text in the shape after the below statement gets executed is "Work stack. Resource: Name1".
MyPPT.Slides(1).Shapes("TextBox 1").TextFrame.TextRange.Find("###").Delete
It's deleting the spaces after the period but I want to keep those spaces i.e. the desired output is "Work stack.<8Spaces>Resource: Name1". Replace(FindWhat:="###", ReplaceWhat:=vbNullString) works really well but I wanted to check whether this is the default behavior of delete method or is it misbehaving or is there a way to change this behavior through ppt textbox properties or some other settings. Please share your thoughts.
Upvotes: 0
Views: 342
Reputation: 50161
This seems to be the intended behavior of Delete
. When done manually the behavior is similar, i.e. if ###
is selected in the textbox, ←Backspace clears the leading white space. The behavior of Cut
is similar.
Maybe use Replace
with a blank string instead of Delete
.
Sub Test()
Dim MyPPT As Presentation
Set MyPPT = ActivePresentation
MyPPT.Slides(1).Shapes("TextBox 1").TextFrame.TextRange.Replace FindWhat:="###", ReplaceWhat:=""
End Sub
Upvotes: 1