Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Finding Text Boxes.

Finding Text Boxes

by Allen Wyatt
(last updated August 28, 2015)

3

Word has a powerful search and replace capability that lets you search for virtually anything in your document. Word even includes codes you can use to search for special items. (Click the Special button in the Find and Replace dialog to see what codes are available.) One thing you cannot search for, however, is text boxes. There is no special code that allows you find text boxes, and you can't search for them using the Object Browser.

You can, however, use a macro to look through a document and stop when it finds a text box. The following macro stops on each text box it finds and asks the user if that is the text box wanted.

Sub SearchTextBox()
    Dim shp As Shape
    Dim sTemp As String
    Dim iAnswer As Integer

    For Each shp In ActiveDocument.Shapes
        If shp.Type = msoTextBox Then
            shp.Select
            Selection.ShapeRange.TextFrame.TextRange.Select
            sTemp = Selection.Text
            sTemp = Left(sTemp,20)
            iAnswer = MsgBox("Box contains text beginning with:" & vbCrLf _
              & sTemp & vbCrLf & "Stop here?", vbYesNo, "Located Text Box")
            If iAnswer = vbYes Then Exit For
        End If
    Next
End Sub

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (3520) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Finding Text Boxes.

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

Starting Out Formulas

When you enter a formula from the keyboard, Excel only knows it is a formula if you start it with an equal sign. You can ...

Discover More

Limiting Choices in a Cell

Want to limit what a person can enter into a particular cell? You can use Excel's data validation feature to help enforce ...

Discover More

Entering Negative Times

Do you need to enter negative times into a worksheet? Excel doesn't really provide a way to do that, but understanding ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (menu)

Wrapping Text Around a Text Box or Frame

Text boxes and frames can be used for all sorts of information and objects in a document. You can wrap text around the ...

Discover More

Columns in a Text Box

Want to divide a text box into columns? Word doesn't allow you to do this, but there are ways to work around the limitation.

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 ...

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 three minus 3?

2016-01-19 06:37:52

Ken Endacott

The macro has a number of shortcomings.

1. The macro searches for textboxes in the main story only. It does not search in other stories such as headers and footers etc. This is a significant shortcoming because textboxes in headers and footers are often used to give sidebars, disclaimer notices and watermarks.

2. Textboxes are not found if they are in groups or canvases.

3. The order that textboxes are found is not necessarily in the order that they appear in the document.

4. Each time the macro is run it finds shapes in the same order. It would be more useful if it re-started the search from the cursor position or the last found textbox.

5. A textbox is a special rectangular shape that has a textframe containing text. Other shapes can also contain textframes with text. It is possible to have a rectangle containing text that looks and feels like a textbox but is not flagged as being a textbox. The following macro will search the main story for any shape including textboxes, that contains text. It will not search inside groups or canvasses.

Sub SearchShapeWithText()
Dim shp As Shape
Dim sTemp As String
Dim iAnswer As Integer
Dim TxtFrame As TextFrame

For Each shp In ActiveDocument.Shapes
Set TxtFrame = shp.TextFrame
If Not TxtFrame Is Nothing Then
If TxtFrame.HasText Then
shp.Select
Selection.ShapeRange.TextFrame.TextRange.Select
sTemp = Selection.Text
sTemp = Left(sTemp, 20)
iAnswer = MsgBox("Shape contains text beginning with:" & vbCrLf _
& sTemp & vbCrLf & "Stop here?", vbYesNo, "Located Text Box")
If iAnswer = vbYes Then Exit For
End If
End If
Next
End Sub


2016-01-18 05:07:48

Mr Red

Thanx 4 code. Doesn't find grouped objects. Not a problem since grouping was only set to layout page by duplicating. (repetitive orthogonal layout) But worth keeping in mind.


2014-12-06 02:43:33

Iqbal Ansari

plz tell me how to convert Text Boxes in to simple text cause when i save the data word into text file. All textbox's matter is save into txt file.

please give me some solution.

Iqbal


This Site

Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon 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.