在PowerPoint VBA中选择幻灯片的一部分 [英] select part of the slide in powerpoint VBA

查看:189
本文介绍了在PowerPoint VBA中选择幻灯片的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以通过给出要选择的区域的坐标,从VBA中选择幻灯片的特定区域.例如,我想选择一个位置为top = 100,left = 100,hight = 10和width = 10的区域,该区域包含3个文本框,我想以某种方式操纵后置词,例如将所有3个文本都左对齐. >

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

Thnx !!!

解决方案

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

is there a way to select a specific area of the slide from VBA by giving the coordinates of the area to be selected. EG I want to select an area with position top=100, left=100, hight=10 and width=10, and this area includes 3 text boxes that I want to manipulate somehow afterwords, say align left all 3 of them.

Particualrly, I have many slides with those 3 boxes, and then some other boxes as well, where the position of those 3 varies +/- 0.3cm from one slide to another, and now I want them to have the same position on all slides. The problem is that I some of them are empty boxes so that I don't know how to search for for them and then include them in the selection, since they don't have the same shape index on all slides. Therefore I thought if there is a code to select a particular area of the slide - that would pretty much solve my problem...

Thnx!!!

解决方案

The FindShapesInSlides code will select all of the shapes (textboxes, etc) in any slide in the slideshow that match the specified boundary (based on top, left, height, width).

You can then add whatever actions you would like to the selected items (like aligning them or whatever).

Select all shapes within a specified boundary (top, left, height, width)

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

Testing the selection

Sub Test()

    FindShapesInSlides pTop:=50, pLeft:=50, pHeight:=100, pWidth:=50

End Sub

这篇关于在PowerPoint VBA中选择幻灯片的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆