Loading
Word.Tips.Net WordTips (Menu Interface)

Finding Text Boxes

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.

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.

Related Tips:

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

Ken Endacott    19 Jan 2016, 06:37
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
Mr Red    18 Jan 2016, 05:07
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.
Iqbal Ansari    06 Dec 2014, 02:43
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
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.