Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. 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: Searching for Floating Graphics.

Searching for Floating Graphics

by Allen Wyatt
(last updated January 2, 2016)

5

Word includes some commands and shortcuts that allow you to search for graphics in your documents. Unfortunately, those methods of searching are only good for finding inline graphics. If you want to find floating graphics, you are out of luck; since they are on the graphics layer and not in the actual document, Word pretty much ignores them.

There is a way you can find floating graphics using a macro, however. A macro can examine the floating graphics in your document and select each of them in turn. The following macro does just that:

Sub FindFigs()
    Dim varItem As Variable
    Dim bExists As Boolean
    Dim iShapeCount As Integer
    Dim iJumpTo As Integer

    ' ensure variable exists
    bExists = False
    For Each varItem In ActiveDocument.Variables
        If varItem.Name = "FigNum" Then
            bExists = True
            Exit For
        End If
    Next varItem

    ' initialize document variable if doesn't exist
    If Not bExists Then
        ActiveDocument.Variables.Add _
          Name:="FigNum", Value:=0
    End If

    ' figure to jump to
    iJumpTo = ActiveDocument.Variables("FigNum") + 1

    ' get number of shapes
    iShapeCount = ActiveDocument.Shapes.Count
    If iJumpTo > iShapeCount Then iJumpTo = 1

    If iShapeCount > 0 Then
        'Display the shape
        ActiveDocument.Shapes(iJumpTo).Anchor.Select
        'Select the shape
        ActiveDocument.Shapes(iJumpTo).Select
    End If
    'Set the variable for next time
    ActiveDocument.Variables("FigNum") = iJumpTo
End Sub

This macro uses a document variable to keep track of which graphic was last selected. If you need to search for floating graphics quite a bit, this means you can assign this macro to the Quick Access Toolbar or a shortcut key and search for each floating graphic in your document, in turn.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (10442) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Searching for Floating Graphics.

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

Printing Just the Visible Data

In a large worksheet, you may want to display and print just a portion of the available data. Displaying the desired ...

Discover More

Selecting a Paper Size

Most of the time we print on whatever is a standard paper size for our area, such as letter size or A4 paper. However, Word ...

Discover More

Spellchecking an Entire Document

Google Docs includes a few tools designed to help improve your writing. One such tool is the spellchecker, which you can use ...

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)

Moving Object Anchors

When you insert an object into your document, it is anchored to a paragraph. If you want to change the paragraph to which the ...

Discover More

Resize Graphics Outside of Word

Need your graphics to be larger or smaller than they first appear when you insert them in a document? Your best bet may be to ...

Discover More

Easily Changing Links in Documents

You may have a lot of linked images in a document, and then one day need to change the links if the location of the images ...

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-08 03:34:43

Ken Endacott

I couldn’t resist fiddling with the macro to add improvements and make it a bit more bulletproof. The following macro will find the next shape even if there are several shapes with the same anchor point.

An anchor contains a list of shapes but the list is not visible nor is it directly accessible in VBA. However with a bit of trickery it is possible to determine the position in the list of a particular shape and advance to the next shape in the list. The order in the list is in the reverse order that the shapes were attached to that anchor.

The macro will find groups and canvases but not the individual shapes within them. If you want to search for shapes in other story ranges such as headers or footers then place the cursor in the header or footer and run the macro. This can uncover hard to find shapes and textboxes that are anchored in headers or footers but are offset into the text body.

By altering a few statements a second macro can be created that will search for previous rather than next shapes.

Sub FindNextShape2()
Dim aAnchor As Range
Dim aShape As Shape
Dim k As Long
Dim j As Long
Dim aShapeName As String
Dim aStory As Range
If Application.Version > 14 Then
MsgBox "This macro will only run in Word 2010 or higher"
Exit Sub
End If
If Val(ActiveDocument.CompatibilityMode) < 14 Then
MsgBox "Warning. Document was created in a version of Word prior to 2010"
End If

aShapeName = "$&$&"
If Selection.ShapeRange.Count > 0 Then
' Check if there are several at the same anchor
Set aShape = Selection.ShapeRange(1)
aShapeName = aShape.Name
Set aAnchor = aShape.Anchor
aAnchor.MoveStart unit:=wdCharacter, Count:=-1
aAnchor.MoveEnd unit:=wdCharacter, Count:=1
k = aAnchor.ShapeRange.Count ' k=number of shapes at anchor

Set aAnchor = aShape.Anchor
aAnchor.MoveStart unit:=wdCharacter, Count:=-1
j = aAnchor.ShapeRange.Count ' j= posn of shape at anchor

If j < k Then
Set aAnchor = aShape.Anchor
aAnchor.MoveStart unit:=wdCharacter, Count:=-1
aAnchor.MoveEnd unit:=wdCharacter, Count:=1
Set aShape = aAnchor.ShapeRange(j + 1)
Selection.Collapse
aShape.Select
Exit Sub
Else ' current shape is the last at the anchor
Selection.ShapeRange(1).Anchor.Select
Selection.MoveStart unit:=wdCharacter
End If
End If

Application.Browser.Target = wdBrowseGraphic
Application.Browser.Next
Selection.MoveStart unit:=wdCharacter, Count:=-1
Selection.MoveEnd unit:=wdCharacter, Count:=1
If Selection.Range.ShapeRange.Count < 1 Then
MsgBox "No shapes beyond this point"
Exit Sub
End If
Set aShape = Selection.Range.ShapeRange(1)
Selection.Collapse
aShape.Select
If aShapeName = aShape.Name Then
MsgBox "No more shapes after this one"
End If
End Sub


2016-01-07 06:48:43

Ken Endacott

The macro instructions to select shapes can be quite complex with the result that a macro to cover all possibilities will be large and complex.

However, the following is a simple macro that will find the next shape from the current cursor position. Its shortcomings are that if there is more than one shape with the same anchor position then only the first is found, and although shapes can be in story types such as headers and footers only the main story (ie the document body) is searched.


Sub FindNextShape()
Dim aShape As Shape
If Selection.ShapeRange.Count > 0 Then
Selection.ShapeRange(1).Anchor.Select
Selection.MoveStart unit:=wdCharacter
End If
Application.Browser.Target = wdBrowseGraphic
Application.Browser.Next
Selection.MoveStart unit:=wdCharacter, Count:=-1
Selection.MoveEnd unit:=wdCharacter, Count:=1
Set aShape = Selection.Range.ShapeRange(1)
Selection.Collapse
aShape.Select
End Sub


2016-01-06 08:37:22

Jennifer Thomas

Ken, thanks for that macro -- when documents are graphic-heavy, this is indeed a more reliable way to find a specific graphic (especially useful for finding non-OCR'd characters/words in a PDF to Word conversion!).


2016-01-05 06:50:40

Ken Endacott

The disadvantage of the FindFigs macro is that it finds graphics in the order that they were inserted into the document, not the order in which they appear.

Browse by graphic will find the next (or previous) graphic in the order that they appear in the document. (actually, it is the order that the anchors appear in the document)

Browse by graphic places the cursor at the graphic's anchor without selecting the graphic and since the graphic could be offset some distance from its anchor it may not be obvious which graphic has been found. If you extend the selection to the whole the paragraph then the graphic will be highlighted but if more than one graphic is anchored at the same point then they will all be highlighted.

It can be confusing when there are multiple graphics with the same anchor point because clicking the browse button again may not move the cursor but it is in fact progressing to the next graphic.

The VBA code for finding and selecting graphics using browser is:

Application.Browser.Target = wdBrowseGraphic
Application.Browser.Next
Selection.MoveStart unit:=wdCharacter, Count:=-1
Selection.MoveEnd unit:=wdCharacter, Count:=2
Selection.Range.ShapeRange(1).Select

or,
Application.Browser.Previous

Browse by graphic can give unexpected results if the document and its graphics were created in a Word version earlier than 2010.


2016-01-04 10:11:04

Jennifer Thomas

Browse by Object for graphics (below the vertical scroll bar) finds the anchor paragraph for floating graphics, so if you follow best practice and anchor your graphics where they are supposed to be and then lock them, this tool is a very easy way to find them.

But locking a graphic is a lot of steps in 2010, so here is a simple little macro I added to my toolbar for that purpose -- hope that saves you as much time as it does for me!

Sub ToggleShapeAnchor()
If Selection.Type = wdSelectionShape Then
For Each Shape In Selection.ShapeRange
Shape.LockAnchor = Not Shape.LockAnchor
Next
End If
End Sub


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.