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

Checking for Sentences Beginning with Conjunctions

In my English classes in junior high, I would get marked down if I started sentences with a conjunction. ("There's a reason ...

Discover More

Removing Add-ins

Add-ins are used to extend Excel's capabilities in lots of different ways. If you want to get rid of an add-in completely, ...

Discover More

Changing Huge Numbers of Hyperlinks

Need to change the various targets of a group of hyperlinks? Getting at the underlying link can seem challenging, but it is ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (menu)

Different Layout for a Portion of a Page

Got a document layout that requires a portion of the page to be in one layout and another portion to be in a different ...

Discover More

Including Text Box Text in Word Counts

If you use text boxes in the layout of your documents, you should know that any word counts you perform do not include any ...

Discover More

Inserting a Text Box

Text boxes are a great way to implement non-standard ways of laying out your document. They allow you to put text at ...

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. 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 2 + 1?

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.