PowerPoint VBA只选择一些形状

时间:2014-05-28 20:27:05

标签: vba powerpoint move shape powerpoint-vba

我正在尝试使用VBA在PowerPoint中创建一个子程序,该子程序将拍摄之前已插入和调整大小的9张图片,并将它们排列成3列和3行。我无法弄清楚如何选择图片,移动它,然后选择幻灯片上的下一张图片。

我的VBA知识主要限于使用Excel,而且由于PowerPoint 2010没有“Record Marco”按钮,这是我目前的可怜尝试。

Sub ArrangeIn3x3()
Dim sldTemp As Slide
Dim lngTemp As Long
Dim lngCount As Long
    For Each sldTemp In ActivePresentation.Slides
        For lngCount = sldTemp.Shapes.Count To 1 Step -1
            With sldTemp.Shapes(lngCount)
                .LockAspectRatio = msoTrue
                .Width = 3 * 72
                .Left = (x + 0.2) * 72
                x = x + 1
                .Top = (y + 0.75) * 72
                y = y + 1
            End With
        Next
    Next
End Sub

谢谢。

1 个答案:

答案 0 :(得分:0)

这是你的3x3网格硬编码;你可以扩展它以获取行/列的数量作为参数,计算第一个图像的大小并自动提供,以及任何其他增强,但这应该做你想要的:

Sub NineUp()

    Dim sngInterRowSpace As Single
    Dim sngInterColSpace As Single
    Dim lRowCount As Long
    Dim lColCount As Long
    Dim sngLeft As Long
    Dim sngTop As Long
    Dim sngImageWidth As Single
    Dim sngImageHeight As Single
    Dim lShapeCount As Long '

    ' Define spacing between rows/columns
    sngInterRowSpace = 0.2 * 72
    sngInterColSpace = 0.2 * 72

    ' change these dimensions to match those
    ' of your images
    sngImageWidth = 2.36 * 72
    sngImageHeight = 2.17 * 72

    lShapeCount = 1
    sngTop = sngInterRowSpace

    For lRowCount = 1 To 3
        sngLeft = sngInterColSpace
        For lColCount = 1 To 3
            With ActivePresentation.Slides(1).Shapes(lShapeCount)
                .Left = sngLeft
                .Top = sngTop
                sngLeft = sngLeft + sngImageWidth + sngInterColSpace
                lShapeCount = lShapeCount + 1
            End With
            'sngTop = sngTop + sngImageHeight + sngInterRowSpace
        Next
        sngTop = sngTop + sngImageHeight + sngInterRowSpace
    Next

End Sub