0

Powerpoint 365 VBA

Set sld = Application.ActiveWindow.View.Slide
Set Shp = sld.Shapes(2)
    If Shp.TextFrame2.HasText Then
        Txt = Replace(Shp.TextFrame2.TextRange.Text, " ", "+")

But this uses ALL the text. I only want to assign a variable to the current SELECTED text.

The ultimate goal would be to check if selection length is > 1, then use the selected text, otherwise use all the text.

2
  • Did you simply mean to use Application.Selection? Commented Oct 8 at 15:17
  • 1
    SO has decided not to let me paste code into an Answer window, so here we are. Put a line break where each | appears and give this a try: Dim oRng As TextRange | Set oRng = ActiveWindow.Selection.TextRange | While InStr(oRng, " ") > 0 | Call oRng.Replace(" ", "+") | Wend Commented Oct 8 at 15:53

1 Answer 1

2

Just use the .Selection.TextRange2.Text itself.

With a slide that looks like this:

enter image description here

This code works for me:

Option Explicit

Sub TEST()
    With ActiveWindow
        If .Selection.Type = ppSelectionText Then
            Debug.Print "before = " & .Selection.TextRange2.Text
            Dim newText As String
            newText = Replace(.Selection.TextRange2.Text, " ", "+", Count:=1)
            .Selection.TextRange2.Text = newText
            Debug.Print "after  = " & .Selection.TextRange2.Text
        End If
    End With
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Used PeterT suggestion. (It was staring me in the face.) Thanks for the assist.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.