【问题标题】:PowerPoint VBA selecting only some shapesPowerPoint VBA 仅选择某些形状
【发布时间】:2014-05-28 20:27:05
【问题描述】:

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

我的 VBA 知识主要限于使用 Excel,并且由于 PowerPoint 2010 没有“记录 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

谢谢。

【问题讨论】:

    标签: vba move shape powerpoint


    【解决方案1】:

    这对您的 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
    

    【讨论】:

      猜你喜欢
      • 2020-09-09
      • 2018-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-01
      • 2020-04-24
      相关资源
      最近更新 更多