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: Counting All Graphics.

Counting All Graphics

Written by Allen Wyatt (last updated August 20, 2022)
This tip applies to Word 2007, 2010, 2013, and 2016


Bob needs to count all the graphics in a document. Some of the graphics are inline and some are floating. Some were inserted as pictures and some were created using the drawing tools in Word. Bob suspects there is somewhere between 150 and 200 graphics in the document, but he'd love a way to get a fast count.

There are a couple of things you can try to get your graphics count. The first thing is to use a simple search and replace. All you need to do is search for ^g and replace with ^&. That finds any graphic and replaces it with whatever was found. In other words, there are no changes to your document. However, Word informs you, when it is done, about how many "replacements" were made. This count is the number of graphics in your document.

The problem with this approach is that it counts only inline images within the document. It does not "find and replace" anything on the drawing layer. To get all the images, you'll need to try a different approach. For instance, you could use the Go To feature of Word. Press F5 to display the Go To tab of the Find and Replace dialog box. If you pick Graphic in the right side of the screen, you can step through the graphics in the document by clicking on the Next button. If you have a bunch of graphics, you could simply put something like +150 in the box and click on Go To. You'll jump to that graphic number, if it is available, and you can then step through the remaining ones, counting as you go.

This approach is better at finding graphics than the find-and-replace approach. It is not perfect, however, as there are places in your document where graphics can be placed that won't be caught by Go To. (Or, honestly, by the Object Browser, which uses the same finding mechanism as Go To.) This approach finds graphics that are inline and on the drawing layer. It does not, however, find them in other places, such as headers or footers. To find those and include them in the count, you'll need to use a macro. The following is a macro that will provide a more inclusive graphics count:

Sub CountGraphics()
    Const sBkMk = "ReturnHere"

    Dim lngSections As Long
    Dim lngSectionCounter As Long
    Dim lngMainDocInlineShapes As Long
    Dim lngMainDocShapes As Long
    Dim lngHdrInlineShapes As Long
    Dim lngHdrShapeRange As Long
    Dim lngFtrInlineShapes As Long
    Dim lngFtrShapeRange As Long
    Dim lngTotalInlineShapes As Long
    Dim lngTotalShapes As Long
    Dim sMsgText As String

    Application.ScreenUpdating = False

    'Get the number of sections in the document.
    lngSections = ActiveDocument.Sections.Count

    'Get the number of inline objects and
    'shape objects in the main document
    lngMainDocInlineShapes = ActiveDocument.InlineShapes.Count
    lngMainDocShapes = ActiveDocument.Shapes.Count

    'Insert a bookmark to return to this place in the document.
    ActiveDocument.Bookmarks.Add sBkMk, Selection.Range

    'Go to the first page of the document.
    Selection.HomeKey wdStory, wdMove

    'Cycle through all of the sections in the document
    'looking in headers and footers for graphics
    For lngSectionCounter = 1 To lngSections
        'Go to the header of the current page
        ActiveDocument.ActiveWindow.View.SeekView = wdSeekCurrentPageHeader
        Selection.WholeStory
        'Get the number of inline objects and shape objects
        lngHdrInlineShapes = lngHdrInlineShapes _
          + Selection.Range.InlineShapes.Count
        lngHdrShapeRange = lngHdrShapeRange _
          + Selection.Range.ShapeRange.Count

        'Go to the footer of the current page
        ActiveDocument.ActiveWindow.View.SeekView = wdSeekCurrentPageFooter
        Selection.WholeStory
        'Get the number of inline objects and shape objects
        lngFtrInlineShapes = lngFtrInlineShapes _
          + Selection.Range.InlineShapes.Count
        lngFtrShapeRange = lngFtrShapeRange _
          + Selection.Range.ShapeRange.Count

        Selection.GoTo wdGoToSection, wdGoToNext
    Next

    'Go to the main body of the document.
    ActiveDocument.ActiveWindow.View.SeekView = wdSeekMainDocument

    'Enable automatic screen updates
    Application.ScreenUpdating = True
    Application.ScreenRefresh

    'Go to the bookmark that was inserted earlier.
    If ActiveDocument.Bookmarks.Exists(sBkMk) Then
        Selection.GoTo wdGoToBookmark, , , sBkMk
        ActiveDocument.Bookmarks(sBkMk).Delete
    Else
        MsgBox "The bookmark '" & sBkMk & "' does not exist."
    End If

    'Calculate the total number of inlineshape objects
    'and (shape and shaperange) objects
    lngTotalInlineShapes = lngMainDocInlineShapes _
      + lngHdrInlineShapes + lngFtrInlineShapes
    lngTotalShapes = lngMainDocShapes _
      + lngHdrShapeRange + lngFtrShapeRange

    'Include the values from the variables into the
    'text of the message
    sMsgText = vbTab & vbTab & "Inline Shapes" _
      & vbTab & "Other Shapes" & vbCr _
      & "Main Document:" & vbTab & lngMainDocInlineShapes _
      & vbTab & vbTab & lngMainDocShapes & vbCr _
      & "Headers:" & vbTab & vbTab & lngHdrInlineShapes _
      & vbTab & vbTab & lngHdrShapeRange & vbCr _
      & "Footers:" & vbTab & vbTab & lngFtrInlineShapes _
      & vbTab & vbTab & lngFtrShapeRange & vbCr _
      & "Total:" & vbTab & vbTab & lngTotalInlineShapes _
      & vbTab & vbTab & lngTotalShapes & vbCr & vbCr _
      & "Note: The values for the headers and the footers " _
      & "could include duplicates."

    'Display the results of the procedure.
    MsgBox sMsgText
End Sub

Note that the macro gets not just the number of graphics in the main document, but also steps through each section in the document and examines the headers and footers for any graphics. There are a couple of things to remember with this macro that can affect the accuracy of the count returned. All of these items are part and parcel to how Word deals with graphics in a document.

  • If the document contains a drawing canvas, it is treated as a single graphic (a shape object), regardless of the number of individual shapes that it contains.
  • Separate shapes are counted separately. When separate shapes are grouped together, then they are counted as a single shape.

Finally, there is one other way in which you can try to get a count of graphics—simply save your document as a Web page (in HTML format). As part of the process of saving in this way, Word saves the graphic files in the document to their own folder. All you need to then do is look at the number of files in the folder and you'll have a good idea of how many graphics were in the document. (How you save a document in HTML format is covered in other WordTips.)

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 (10388) 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: Counting All 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

Deleting Paragraph Borders

Got a document that has a border around some paragraphs? Here's how you can get rid of the border using the tools on the ...

Discover More

Converting Numeric Values to Times

If you have a bunch of times entered into cells without the colon between the hours and minutes, chances are good that ...

Discover More

Summing Based on Part of the Information in a Cell

Excel provides a variety of tools that allow you to perform operations on your data based upon the characteristics of ...

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 (ribbon)

Selecting a Graphic that is Behind Text

Position a graphic so that it is "behind" your text, and it may seem like you can no longer select the graphic. Here's ...

Discover More

The Changing Relationship of WordArt and Text Boxes

Two of the long-time features in Word are text boxes and WordArt. You might not think these two are related, but they are ...

Discover More

Scaling Graphics in a Macro

If you need to make sure that the graphics in a document are all scaled similarly, you'll love the macros presented in ...

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}] (all 7 characters, in the sequence shown) 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 two more than 7?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.

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