If you do a lot of work with documents from other people, you may have a need to remove text boxes in those documents. If there are only one or two text boxes in the document, it is not that difficult to select them and delete them. What if there are 30, 40, or more text boxes, though? Deleting them individually can quickly get tedious.
One potential solution is a "brute force" method. Follow these steps:
- In your document, press Ctrl+A. The entire document is selected.
- Press Ctrl+C. The document is now on the Clipboard.
- Open a new, blank document.
- Choose Paste Special from the Edit menu. Word displays the Paste Special dialog box. (See Figure 1.)
Figure 1. The Paste Special dialog box.
- In the list of formats, choose Unformatted Text.
- Click on OK.
The document text, minus the text boxes, is now in the new document. The obvious drawback to this approach is that the other formatting of the original document is also lost, and you must reformat the entire document. (I told you this was a brute force method.)
If you want to get rid of only the text boxes, then the quickest solution is to use a macro. The following macro will quickly remove all text boxes in your document:Sub RemoveTextBox1() Dim shp As Shape For Each shp In ActiveDocument.Shapes If shp.Type = msoTextBox Then shp.Delete Next shp End Sub
You should realize that this macro removes all of the text boxes and their contents. In other words, if a text box is used for placement of text, then the text in that text box is deleted along with the text box itself.
If you prefer to transfer the text from the text boxes to the document, prior to deleting the text box, then a slight modification on the above macro will work:Sub RemoveTextBox2() Dim shp As Shape Dim oRngAnchor As Range Dim sString As String For Each shp In ActiveDocument.Shapes If shp.Type = msoTextBox Then ' copy text to string, without last paragraph mark sString = Left(shp.TextFrame.TextRange.Text, _ shp.TextFrame.TextRange.Characters.Count - 1) If Len(sString) > 0 Then ' set the range to insert the text Set oRngAnchor = shp.Anchor.Paragraphs(1).Range ' insert the textbox text before the range object oRngAnchor.InsertBefore _ "Textbox start << " & sString & " >> Textbox end" End If shp.delete End If Next shp End Sub
When this macro is done, you can do a search for "Textbox start" and you will be at the beginning of text that used to be in the text boxes that are now gone from your document. You can then edit the text so that it appears as you want.