如何将内容占位符逐行拆分为文本形状powerpoint 2010

时间:2015-07-01 15:28:47

标签: vba powerpoint-2010

我是vb和power point的新手,试图在 power point 2010 中运行宏。我想要实现的是,当宏运行时,它应该逐行拆分内容占位符区域中的内容,并将每一行放在一个新的文本框形状中。

我做了一些工作,但无法继续前进。宏功能在

之下
Sub HelloWorldMacro()

Dim Sld As Slide
Dim Shp As Shape
' Current slide
Set Sld = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex)

For Each s In Sld.Shapes
    ' Condition - not to grab contents from title area.
    If s.Name <> "Title 1" Then
        If s.HasTextFrame Then
            With s.TextFrame
                If .HasText Then MsgBox .TextRange.Text
            End With
        End If
    End If
Next
End Sub 

通过这个我能够将内容区域的文本抓取到一个msg框中。但是无法将其拆分并将其放置在文本形状区域中。

还尝试了一些形状创建功能,但无法将它们组合起来。

Sub create_shape()

Dim Sld As Slide
Dim Shp As Shape

Set Sld = ActivePresentation.Slides(ActiveWindow.View.Slide.SlideIndex)

Set Shp = Sld.Shapes.AddShape(Type:=msoShapeRectangle, _
    Left:=24, Top:=65.6, Width:=672, Height:=26.6)

    Shp.Name = "My Header"
    Shp.Line.Visible = msoFalse
    Shp.Fill.ForeColor.RGB = RGB(184, 59, 29)
End Sub

1 个答案:

答案 0 :(得分:1)

这将向您展示如何在文本框中获取每一行或一段:

Sub LineByLine()
    Dim oSh As Shape
    Dim x As Long
    ' for example only:
    Set oSh = ActiveWindow.Selection.ShapeRange(1)

    With oSh.TextFrame.TextRange
        For x = 1 To .Paragraphs.Count
            MsgBox .Paragraphs(x).Text
        Next
        For x = 1 To .Lines.Count
            MsgBox .Lines(x).Text
        Next
    End With
End Sub