Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Removing All Text Boxes In a Document.

Removing All Text Boxes In a Document

by Allen Wyatt
(last updated September 7, 2013)

23

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:

  1. In your document, press Ctrl+A. The entire document is selected.
  2. Press Ctrl+C. The document is now on the Clipboard.
  3. Open a new, blank document.
  4. Make sure the Home tab of the ribbon is displayed.
  5. Click the down-arrow under the Paste tool (at the left side of the ribbon) and choose Paste Special. Word displays the Paste Special dialog box. (See Figure 1.)
  6. Figure 1. The Paste Special dialog box.

  7. In the list of formats, choose Unformatted Text.
  8. 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. Understand, as well, that anything "special" in the text—such as tables—is converted to regular text by the macro. This means that the macro may result in a fair amount of work that needs to be done in formatted the transferred text.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (9169) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Removing All Text Boxes In a Document.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Generating Unique Sequential Numbers

Using Excel to generate unique sequential numbers for invoices or company statements can be a challenge. Here's information ...

Discover More

Adding a Report

The Report Manager allows you to create specialized reports that can be easily printed from your worksheet data. This tip ...

Discover More

Including Headers and Footers when Selecting All

If you are creating a macro that, in the course of processing your document, needs to update all the fields in the document, ...

Discover More

The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!

More WordTips (ribbon)

Resizing a Text Box

Text boxes allow you to "segment" information in your document and lay it out differently. You can easily resize these boxes ...

Discover More

Finding an Invisible Text Box

Text boxes can be a great aid in designing the layout of your document. What do you do when you can't find a text box that ...

Discover More

Wrapping Text around a Graphic in a Text Box

Word allows you to wrap text around a graphic or around a text box, but it won't allow you to wrap text in a text box around ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 - 0?

2016-11-22 14:14:21

Karen Warseck

This is WONDERFUL!!!!!!!!!!!!

Now if you can only make it retain the formatting, I will be in heaven.


2016-01-27 11:57:25

Ken Endacott

Why are you against textboxes?
They can be very useful.


2016-01-25 08:42:59

Robert S. Rawding

Whose idea, in God's name, was it to "invent" text boxes anyway. This is some kind of archaic holdover from keypunch days I guess. VERY STUPID.

--Bob--


2015-10-21 22:04:46

Jim

At first, the VBA did not work for me. I'm using Word 2010.

Eventually realized that the problem was that my .docx file was in Word 2007 format (compatibility mode). Once I converted it to Word 2010 format, the VBA worked!


2015-09-03 10:10:42

Joe

Worked perfectly for me in Word 2010, Ken. Thank you.


2015-06-26 09:24:58

vanda

Hi,
yes, but still getting error in following line
Selection.TypeText(txt) - reference to a non-shared member required an object refernce

and

For Each shp As Microsoft.Office.Interop.Word.Shape In Document.Shapes - variable shp hides a variable in an enclosing block


2015-06-25 09:10:25

Ken Endacott

Vanda

Are you using VBA. You seem to be using VB.


2015-06-25 03:28:04

vanda

Hi Ken Endacott,

i am sorry for so many queries, i am new to this. Please share c# code of the below macro. i am getting lots of errors like
1 - msoTextBox- does not exist in current context

2-Shape shp = default(Shape);
foreach (shp in document.Shapes) - The type or namespace "shp" cannot be found

3 - Selection.TypeText txt; - C# equvivalent code for this line.
Please guide me. :(

Thankyou


2015-06-25 02:17:06

vanda

Hi, thankyou soo much for you answer.
i getting an error on following line

1 - foreach ( shp in ActiveDocument.Shapes) - (error msg-ActiveDocument does not exist in current context)

I have added reference of following
using Microsoft.Office.Interop;
using Microsoft.Office.Tools.Word;
using Microsoft.Office.Interop.Word;

if possible please share C# code of the same. If C# is not possible then please atleast give me a solution of ActiveDocument.

Thankyou


2015-06-24 05:41:49

Ken Endacott

The following macro will remove textboxes and put their content at what was the anchor point of the textbox. As it stands it works only on textboxes and not on shapes containing text frames.

Sub RemoveBoxFromText()
Dim shp As Shape
Dim txt As String
For Each shp In ActiveDocument.Shapes
If shp.Type = msoTextBox Then
shp.Select
txt = shp.TextFrame.TextRange.Text
shp.Delete
Selection.TypeText txt
End If
Next shp
End Sub


2015-06-24 04:16:55

vanda

hi,
i want to delete shapes and replace the content on the shape at the same postion as it is. For example - in a doc file , i have a textbox with some content. I just want to remove the textbox and want to put/insert content of textbox on the same position where the textbox was.
Hope u understood my question. Please guide me for the same.


2015-05-21 19:37:23

David Lackowski

It seem like a lot of work to accomplish something that should be done much more simply. Not worth the bother!


2015-05-11 01:55:30

Dianne DeSha

Thanks, Ken! Finally worked for me! :)


2015-04-28 09:04:07

Ken Endacott

The macros have problems.

The first problem is that the macros will not delete all the textboxes in one pass because as a shape is deleted the number left decreases and ActiveDocument.Shapes.Count changes. The solution is to delete in reverse order.

The second problem is that only textboxes in the document body are deleted. There can also be textboxes in other story parts such as headers and footers.

The third problem is that text can appear in shapes other than textboxes. If the shape is a rectangle then it looks like a textbox but isn’t.

The macro below is a replacement for RemoveTextBox1. It will delete all textboxes and their contents wherever they are and delete the text only from other shapes that contain text.

Sub RemoveTextBox1()
Dim shp As Shape
Dim stry As Range
Dim oTxtFrame As TextFrame
Dim j As Long
Dim k As Long
For Each stry In ActiveDocument.StoryRanges
j = stry.ShapeRange.Count
For k = j To 1 Step -1
Set shp = stry.ShapeRange(k)
If shp.Type = msoTextBox Then
shp.Delete
Else
Set oTxtFrame = shp.TextFrame
If oTxtFrame Is Nothing Then
' shape does not have a text frame
Else
If oTxtFrame.HasText Then
oTxtFrame.TextRange.Text = "" ' deletes the text but not the shape
' shp.Delete will delete the shape including its text
End If
End If
End If
Next k
Next stry
End Sub


2015-04-27 18:07:43

Bob Fast

For god's sake how do you just delete an unwanted box in word??? Wthout macros, without losing formatting... just get rid of it!


2015-04-10 11:35:38

Marcia

If you want to remove all shapes from a document, you can use this macro:

Sub RemoveAllShapes()
ActiveDocument.Shapes.SelectAll
Selection.Delete
End Sub

The For-Each loop in the article did not work for me, but this does.


2015-02-17 11:15:02

Charlotte

The remove formatting option worked for me using Word 2010. Thank you.


2015-01-24 00:12:04

Rajiv Kamal

Usless stuff.

Fr name sake it removes the text box. property of the text inside text box still remains the same.

i.e. after running the macro successfully, the text behaves in the same manner.


2015-01-16 18:29:19

mark

The Paste Special, Unformatted Text option doesn't work. I have Word 2010. Just gives me two blank pages.


2014-11-12 10:07:00

Richard

This macro didn't work for me, either. It just blew the formatting all over the place and left the text in text boxes. Using Word 2013.


2014-10-25 15:28:09

L

tried 3 times, it only increased the background formatting


2014-03-16 19:46:15

adrian

Worked for me using word 2010.

Unfortunately the anchor point is the top of the page.

Is it possible to set the insertion point of the range object using 'shp.Left' and 'shp.Top' to get the text in the something like the right place?


2013-12-24 15:38:44

kathy

This tip did not work for me. I have Word 2007. I tried the macro to remove all textboxes but leave the text.


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.