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

后端 未结 4 1983
温柔的废话
温柔的废话 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 22:15

    This gets a little dirty as I have to change/restore relative positioning/sizing in order to get absolute page positioning. Also, changing shapes mess up enumeration, so must refer shapes by names:

    Sub DeleteEveryPageTopAndBottomShape()
        Dim p As Page, r As Rectangle, s As Shape
        Dim rvp As WdRelativeVerticalPosition, rvs As WdRelativeVerticalSize
        Dim top_s As String, bottom_s As String
        For Each p In ThisDocument.ActiveWindow.ActivePane.Pages
            top_s = vbNullString
            bottom_s = vbNullString
            For Each r In p.Rectangles
                If r.RectangleType = wdShapeRectangle Then
                    For Each s In p.Rectangles(1).Range.ShapeRange
                        rvp = s.RelativeVerticalPosition
                        s.RelativeVerticalPosition = wdRelativeVerticalPositionPage
                        s.RelativeVerticalSize = wdRelativeVerticalSizePage
                        If Len(top_s) Then
                            If s.Top < ThisDocument.Shapes(top_s).Top Then top_s = s.Name
                        Else
                            top_s = s.Name
                        End If
                        If Len(bottom_s) Then
                            If s.Top + s.Height > ThisDocument.Shapes(bottom_s).Top + ThisDocument.Shapes(bottom_s).Height Then bottom_s = s.Name
                        Else
                            bottom_s = s.Name
                        End If
                        s.RelativeVerticalPosition = rvp
                        s.RelativeVerticalSize = rvs
                    Next
                End If
            Next
            Debug.Print "..."
            If Len(top_s) Then ThisDocument.Shapes(top_s).Delete
            If bottom_s <> top_s Then ThisDocument.Shapes(bottom_s).Delete
        Next
    End Sub
    

提交回复
热议问题