ms word 2010 macro How to select all shapes on a specific page

后端 未结 4 2026
温柔的废话
温柔的废话 2021-01-16 21:38

The command ActiveDocument.Pages(1).Shapes.Range.Select doesnot seem to work in word 2010. (It used to work in word 2003).

I need to select all the shapes on a speci

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-16 21:54

    This should do what you want. It deletes the shape with the highest top on the page and the shape with the lowest bottom from each page. It's a very naive implementation, because I'm not familiar with Word, but given that my earlier code worked for you, there's a reasonable chance this will do what you want.

    Sub removeTopAndBottomMostShapesFromActiveDocument()
    
        Dim shape As shape
        Dim topShape As shape
        Dim bottomShape As shape
    
        Dim pageNum
        For pageNum = 1 To ActiveWindow.Panes(1).Pages.Count
    
            Dim highestPoint, lowestPoint
            highestPoint = 999999
            lowestPoint = -999999
    
            Set topShape = Nothing
            Set bottomShape = Nothing
    
            Dim sr As ShapeRange
            Set sr =  ActiveWindow.Panes(1).Pages(pageNum).Rectangles.Item(1).Range.ShapeRange
            sr.Select
            For Each shape In sr
                If shape.Top < highestPoint Then
                    Set topShape = shape
                    highestPoint = shape.Top
                End If
                If shape.Top + shape.Height > lowestPoint Then
                    Set bottomShape = shape
                    lowestPoint = shape.Top + shape.Height
                End If
            Next
    
            If Not topShape Is Nothing Then
                topShape.Delete
            End If
            If Not bottomShape Is Nothing Then
                bottomShape.Delete
            End If
    
        Next
    
    End Sub
    

提交回复
热议问题