Results 1 to 4 of 4

Thread: Removing lines

  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Thumbs down Removing lines

    We scan documents and after running OCR, our documents often have a number of lines when we open the RTF in Word. I have written a macro to delete the lines:

    Dim s As Shape
    Dim i As InlineShape

    For Each s In ActiveDocument.Shapes
    s.Delete
    Next
    For Each i In ActiveDocument.InlineShapes
    i.Delete
    Next

    This code deletes about 80% of the lines. When I select any of the remaining lines, right-clicking shows them as "AutoShapes", but there's no AutoShapes collection which I can work with.

    What collections other than Shapes and InlinShapes might I try?

    Thanks.

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    AutoShapes ought to fit in one of those collections or the other.

    Have you by any chance tried right-clicking on one of the lines that the macro does delete, prior to running the macro to delete it? (wonder if they all would identify as AutoShapes).

    Also, I wonder if the 20% remaining lines might have to do with the potential indexing problems that can occur when looping through a collection to delete all of the items.
    What happens if you run this code instead?
    Code:
    Dim s As Long
    Dim i As Long
    
    For s = ActiveDocument.Shapes.Count To 1 Step -1
       ActiveDocument.Shapes(s).Delete
    Next
    For i = ActiveDocument.InlineShapes.Count To 1 Step -1
       ActiveDocument.InlineShapes(i).Delete
    Next
    If that doesn't help either, could you post a brief, sanitized portion of a document containing the problem AutoShapes?

    Gary
    Last edited by Gary Frieder; 2012-01-07 at 01:39. Reason: fixed typos in code

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    Of course!!! The reverse loop did it. I simply didn't think of it. Thank you for reminding me.

  4. #4
    New Lounger
    Join Date
    Dec 2009
    Location
    Goulburn. NSW, Australia
    Posts
    20
    Thanks
    3
    Thanked 4 Times in 4 Posts
    What about ...

    Do While ActiveDocument.Shapes.Count > 0
    ActiveDocument.Shapes(1).Delete
    Loop
    Do While ActiveDocument.InlineShapes.Count > 0
    ActiveDocument.InlineShapes(1).Delete
    Loop

Posting Permissions

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