首页 文章

Powerpoint VBA可选择幻灯片特定区域内的所有形状

提问于
浏览
2

我想在powerpoint中运行一个允许以下步骤的宏:

  • 对于活动演示文稿中的每个幻灯片,在尺寸标注内选择幻灯片的区域

  • 将所有对象(形状,文本框等)分组,但不要在尺寸维度内对图像(emf,jpg,png)进行分组

  • 取消组合

我是ppt vba的新手 . 到目前为止,我做了一些研究后,在每个幻灯片上为一个选定的对象创建了一个 .

感谢帮助!

Public Sub ResizeSelected()
On Error Resume Next
Dim shp As Shape

If ActiveWindow.Selection.Type = ppSelectionNone Then
  MsgBox "select a grouped", vbExclamation, "Make Selection"
Else
  Set shp = ActiveWindow.Selection.ShapeRange(1)

With ActiveWindow.Selection.ShapeRange
 .Width = 12.87
 .Left = 0.23
 .Ungroup
End With
End If
End Sub

2 回答

  • 0

    您可以自行更改大小,取消分组和显示消息框 . 这将有助于选择和分组形状 . 根据需要更改传递给IsWithinRange的值,如果愿意,可以向案例选择器添加更多形状类型;我刚刚添加了一些典型的类型 . 您肯定想要排除占位符,表格等,因为它们不能与其他形状分组 .

    Sub Thing()
        Dim oSl As Slide
        Dim oSh As Shape
    
        For Each oSl In ActivePresentation.Slides
            For Each oSh In oSl.Shapes
                If IsWithinRange(oSh, 0, 0, 200, 200) Then
                    ' Don't select certain shapes:
                    Select Case oSh.Type
                        Case 1, 6, 9
                            ' add the shape to the selection
                            oSh.Select (False)
                        Case Else
                            ' don't include it
                    End Select
                End If
            Next
            ActiveWindow.Selection.ShapeRange.Group
        Next
    End Sub
    
    Function IsWithinRange(oSh As Shape, _
        sngLeft As Single, sngTop As Single, _
        sngRight As Single, sngBottom As Single) As Boolean
    ' Is the shape within the coordinates supplied?
    
        With oSh
            Debug.Print .Left
            Debug.Print .Top
            Debug.Print .Left + .Width
            Debug.Print .Top + .Height
            If .Left > sngLeft Then
                If .Top > sngTop Then
                    If .Left + .Width < sngRight Then
                        If .Top + .Height < sngBottom Then
                            IsWithinRange = True
                        End If
                    End If
                End If
            End If
        End With
    
    End Function
    
  • 0
    Dim oSl As Slide
    Dim oSh As Shape
    
    For Each oSl In ActivePresentation.Slides
    For Each oSh In oSl.Shapes
      If IsWithinRange(oSh, -1, 0.5, 13.5, 7.4) Then
        ' Don't select certain shapes:
        Select Case oSh.Type
        Case msoGroup, msoChart, msoAutoShape, msoLine, msoDiagram, msoEmbeddedOLEObject
      ' add the shape to the selection
        oSh.Select (False)
        Case Else
        ' don't include it
        End Select
       End If
       Next
       ActiveWindow.Selection.ShapeRange.Group.Select
    
    Next oSl
    End Sub
    
    Function IsWithinRange(oSh As Shape, _
    sngLeft As Single, sngTop As Single, _
    sngRight As Single, sngBottom As Single) As Boolean
    ' Is the shape within the coordinates supplied?
    
    With oSh
        Debug.Print .Left
        Debug.Print .Top
        Debug.Print .Left + .Width
        Debug.Print .Top + .Height
        If .Left > sngLeft Then
            If .Top > sngTop Then
                If .Left + .Width < sngRight Then
                    If .Top + .Height < sngBottom Then
                        IsWithinRange = True
                    End If
                End If
            End If
        End If
     End With
    End Function
    

相关问题