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

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

Pictures in AutoShapes

Filling an AutoShape with a picture of your choosing is a neat trick. Excel makes it easy to do.

Discover More

Setting Orientation of Cell Values

Need the contents of a cell to be shown in a direction different than normal? Excel makes it easy to have your content appear ...

Discover More

Referencing the Last Six Items in a Formula

If you have a list of data in a column, you may want to determine an average of whatever the last few items are in the ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (menu)

Creating Sideheads

A sidehead can be used as a layout element for a document. You can create sideheads in a document by using text boxes, as ...

Discover More

Selecting Text in Linked Text Boxes

Text boxes are often used as design elements in a document layout. If you have linked text boxes, you may have noticed that ...

Discover More

Adding Sidebars

When designing your document, you may want to use sidebars like you see in magazines and some books. This tip explains the ...

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 8Mpixels. 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 more than 5?

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.