Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Sep 2013
    Thanked 0 Times in 0 Posts

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

    I need to delete the first and the last shape on each and every page of a 300+ page word document. (The shapes do not occur in the header / footer).
    My approach is to select all shapes occurring on one page. Delete the first and the last shape. Then go to the next page (i.e. loop through the pages).
    I tried

    (this comand i picked up from the msdn vba reference office 2003).
    It doesnot work in word 2010.

    What would be the equivalent command in word 2010?

    Thanks for taking time to read through this post.


  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    New Lounger
    Join Date
    Dec 2009
    Verona, WI
    Thanked 0 Times in 0 Posts
    I cannot provide a way with code to pick the first and last shape on a particular page but the following code will help you step through and delete them one by one. As written, this works with text boxes.

    Sub TextBoxDeleteOneByOne()
    ' Scroll through all text boxes, delete if directed to
    Dim shp As Shape, intNbrShapes As Integer, vResponse As Variant
    Dim strBoxNbr As String, intBoxNbr As Integer, strMsg As String

    intNbrShapes = 0
    For Each shp In ActiveDocument.Shapes
    If shp.Type = msoTextBox Then
    intNbrShapes = intNbrShapes + 1
    ' Scroll through the active document so that the current selection is visible in the document window.
    ActiveWindow.ScrollIntoView Selection.Range, True
    strMsg = shp.TextFrame.TextRange.Text

    vResponse = MsgBox("Text box name: " & shp.Name & vbCrLf & "Text Contents: " & strMsg & vbCrLf & "Delete?", vbYesNoCancel, "Finding Text Boxes")
    If vResponse = vbYes Then ' User chose Yes.
    If vResponse = vbCancel Then
    Exit Sub
    End If
    End If
    End If
    Next shp

    End Sub

  4. #3
    Star Lounger
    Join Date
    Feb 2011
    Washington, DC
    Thanked 5 Times in 5 Posts
    The shapes collection in a Word document applies to the entire story (i.e. the main body or the headers and footers), and is not divided by pages. Pages don't have a shapes collection. Shapes per se don't have a page property either.

    What might work, and I don't have time to test this, is to work with the Information property of the shape's range.

    What you are going to have to do is iterate through the shapes in the document and select each one. Use the range.information(wdActiveEndPageNumber) property to determine the page that the shape is on. Cache that information. Then iterate until the page number changes. That shape is at the top of the page. To find the shape at the bottom of the page, iterate until the property changes, then back up one shape. That shape is at the bottom of a page.

    BUT there is a conceptual problem. Unless you are using hard page breaks, when you delete a shape you will probably change the page divisions. How will you handle that?

    Maybe someone else has a better solution.

    - Jessica

  5. #4
    New Lounger
    Join Date
    Oct 2013
    Thanked 0 Times in 0 Posts
    you can use this code

    Sub SelectAllShapes()

    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts