简体   繁体   中英

Shift text in Power Point 2007 text box using VBA

I need to shift the position of text in all textboxes (1 textbox per slide). The subtitles' first language is in white and there's English in yellow. Now I'd like yellow to be on top, white below. So first I'd like to select white, copy, erase, go to the end of yellow and paste (with line break between white/yellow). Can it be done?

Maybe some change to such script would help?

Sub RemoveWhiteText()

    Dim oSl As Slide
    Dim oSh As Shape


    With ActivePresentation

For Each oSl In .Slides
    For Each oSh In oSl.Shapes
        With oSh
            If .HasTextFrame Then
                If .TextFrame.HasText Then
                    If TextRange.Font.Color = vbWhite Then
                        oSh.TextFrame.Text
                    End If
                End If
            End If
        End With
    Next
Next

    End With
End Sub

This will move the first run with font color white to the end of the text box. Try this:

Sub MoveWhiteTextToEnd(oSh As Shape) With oSh With oSh.TextFrame.TextRange.Runs(1) If .Font.Color.RGB = vbWhite Then .Cut oSh.TextFrame.TextRange.InsertAfter (vbCrLf) oSh.TextFrame.TextRange.Characters(oSh.TextFrame.TextRange.Length + 1).Paste End If End With End With End Sub

Update your code with this call:

If .TextFrame.HasText Then Call MoveWhiteTextToEnd(oSh) End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM