首页 文章

在powerpoint VBA中选择幻灯片的一部分

提问于
浏览
0

有没有办法通过给出要选择的区域的坐标从VBA中选择幻灯片的特定区域 . EG我想选择一个位置top = 100,left = 100,hight = 10和width = 10的区域,这个区域包括3个文本框,我想以某种方式操作后面的文字,比如左边所有3个 .

特别是,我有很多幻灯片,包括这3个盒子,还有其他一些盒子,这些盒子的位置从一张幻灯片到另一张幻灯片变化/ - 0.3厘米,现在我希望它们在所有幻灯片上都有相同的位置 . 问题是我有些是空盒子,因此我不知道如何搜索它们然后将它们包含在选择中,因为它们在所有幻灯片上没有相同的形状索引 . 因此,我想如果有一个代码来选择幻灯片的特定区域 - 这几乎可以解决我的问题......

日Thnx !!!

1 回答

  • 0

    FindShapesInSlides 代码将选择幻灯片中任何与指定边界匹配的幻灯片中的所有形状(文本框等)(基于顶部,左侧,高度,宽度) .

    然后,您可以向所选项添加您想要的任何操作(例如对齐它们或其他任何内容) .

    选择指定边界内的所有形状(顶部,左侧,高度,宽度)

    Sub FindShapesInSlides(pTop As Single, pLeft As Single, pHeight As Single, pWidth As Single)
    
        Dim slideShapes As Shapes
        Dim slideShape As Shape
    
        'Loop through each slide in the presentation
        For i = 1 To ActivePresentation.Slides.Count
    
            'Get shapes for the slide
            Set slideShapes = ActivePresentation.Slides(i).Shapes
    
            'Remove any existing selection
            ActiveWindow.Selection.Unselect
    
            'Loop through the shapes
            For Each slideShape In slideShapes
    
                'Check if shape is within the specified boundary
                If ((slideShape.top >= pTop And slideShape.top <= (pTop + pHeight)) _
                    And (slideShape.left >= pLeft And slideShape.left <= (pLeft + pWidth))) Then
    
                    'Add the shape to the current selection
                    slideShape.Select (msoFalse)
    
                End If
            Next slideShape
        Next i
    
    End Sub
    

    测试选择

    Sub Test()
    
        FindShapesInSlides pTop:=50, pLeft:=50, pHeight:=100, pWidth:=50
    
    End Sub
    

相关问题