Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Mar 2016
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Ways to remove (lots of) empty text boxes from docx?

    Hello.
    For my work as a translator I often have to convert pdf files to docx. Usually, the conversion produces reasonably "clean" files that require little additional editing before I can go to work on translating the content.
    For whatever reason, the latest such conversion has not worked out so well: the docx contains LOTS of empty text boxes.
    (I can tell they are there, because with my settings I can see a paragraph marker in each of them, which means the customer may see them as well. Can't have that, unfortunately).

    Now, under normal circumstances, I would simply go through the whole document and remove the empty text boxes manually, one by one. In this case, however, there are 10 to 20 of them on each page, and the doc has 139 pages total... So here I am, hoping that somebody may have an idea on how to accelerate or even automate this otherwise tedious process.

    I am using Word 2007, and I need the actual content (whether in text boxes or not, and most of it IS in text boxes as well) to remain untouched.

    Any thoughts?
    Thanks in advance!

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Assuming they are textboxes and not frames, you could use a macro like:
    Code:
    Sub Demo()
    Application.ScreenUpdating = False
    Dim i As Long
    With ActiveDocument
      For i = .Shapes.Count To 1 Step -1
        With .Shapes(i)
          If Not .TextFrame Is Nothing Then
            If Trim(.TextFrame.TextRange.Text) = vbCr Then .Delete
          End If
        End With
      Next
    End With
    Application.ScreenUpdating = True
    End Sub
    But, if they're frames (which is more common with PDF converters), you'll need:
    Code:
    Sub Demo()
    Application.ScreenUpdating = False
    Dim i As Long
    With ActiveDocument
      For i = .Frames.Count To 1 Step -1
        With .Frames(i)
          If Trim(.Range.Text) = "" Then .Cut
        End With
      Next
    End With
    Application.ScreenUpdating = True
    End Sub
    Last edited by macropod; 2016-03-11 at 19:34.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    New Lounger
    Join Date
    Mar 2016
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First of all, thanks for your reply!
    They are definitely text boxes, not frames.
    I tried the macro you posted, but running it produces:

    Run-time error '5917':
    This object does not support attached text
    the 'Debug' button highlights line 8 as the culprit:
    If Trim(.TextFrame.TextRange.Text) = vbCr Then .Delete

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    The code works just fine for me, though I've just found it deletes some other shape objects, too. Try:
    Code:
    Sub Demo()
    Application.ScreenUpdating = False
    Dim i As Long
    With ActiveDocument
      For i = .Shapes.Count To 1 Step -1
        With .Shapes(i)
          If Not .TextFrame Is Nothing Then
            If .TextFrame.HasText Then
              If Trim(.TextFrame.TextRange.Text) = vbCr Then .Delete
            End If
          End If
        End With
      Next
    End With
    Application.ScreenUpdating = True
    End Sub
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    New Lounger
    Join Date
    Mar 2016
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much, that seems to have done the trick!

Posting Permissions

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