1

我正在尝试将 PPT 形状导出到图像文件中,但是,PowerPoint 正在将形状重新调整为文本长度。

我知道 VBA 中有 Autosize 功能,但是我无法在 PowerPoint 2013 中使用 msoAutoSizeTextToFitShape 功能。

我的代码如下

Sub RunMe()
    Dim MyShape As Shape
    Dim i As Integer
    Dim S(0 To 2) As String

    Set MyShape = ActivePresentation.Slides(1).Shapes.AddShape(msoShapeRectangle, 50, 50, 100, 40)
    S(0) = "short text"
    S(1) = "Medium length text"
    S(2) = "Really Really Long and descriptive Text"
        For i = 0 To 2
            With MyShape
                '.TextFrame.AutoSize = PowerPoint.ppAutoSizeMixed
                .TextFrame.TextRange.Text = S(i)
                .Export "C:\temp\" & "\" & S(i) & ".png", ppShapeFormatPNG
            End With
        Next i
End Sub

正如您将看到的,生成的图像尺寸是不同的。有没有办法创建相同大小的图像?

4

2 回答 2

0

我在当前 PC 上安装了 2003 版,因此以下内容未经测试

根据一些网站,TextFrame2是从 2007 年开始的新物业。

你可以试msoAutoSizeTextToFitShape一下TextFrame2

编辑 :

我在我的家用电脑上用 2010 版试过这个,看起来还不错。试试看。TextFrame在您的代码中替换为TextFrame2

于 2013-09-26T09:34:20.883 回答
0

您可以调整文本大小以确保它适合形状或调整形状以适合文本大小。我的猜测是你会想要前者,所以试试这个:

Sub RunMe()
    Dim MyShape As Shape
    Dim i As Integer
    Dim S(0 To 2) As String
    Dim sngOriginalSize As Single

    Set MyShape = ActivePresentation.Slides(1).Shapes.AddShape(msoShapeRectangle, 50, 50, 100, 40)
    S(0) = "short text"
    S(1) = "Medium length text"
    S(2) = "Really Really Long and descriptive Text"
        For i = 0 To 2
            With MyShape
                .TextFrame.TextRange.Text = S(i)

                ' store original text size
                sngOriginalSize = .TextFrame.TextRange.Font.Size

                ' decrement font size until the text fits
                ' within the shape:
                Do While .TextFrame.TextRange.BoundHeight > MyShape.Height
                    .TextFrame.TextRange.Font.Size = .TextFrame.TextRange.Font.Size - 1
                Loop

                .Export "C:\temp\" & "\" & S(i) & ".png", ppShapeFormatPNG

                ' reset the text to original size
                .TextFrame.TextRange.Font.Size = sngOriginalSize
            End With
        Next i
End Sub
于 2013-09-26T16:12:48.300 回答