Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. 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: Extracting INCLUDEPICTURE File Names.

Extracting INCLUDEPICTURE File Names

Written by Allen Wyatt (last updated February 9, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


When working with long documents that contain graphics, it is not unusual to use the INCLUDEPICTURE field to actually insert the graphics into the document. If you have a large number of these fields in your document, you may want a way to create an "art list" that includes the names of the graphic files used in the document.

By using a relatively simple macro, you can step through each instance of the INCLUDEPICTURE field in your document and extract just the names of the files referenced. These can then be added to a new document, so that when the macro is done, the new document contains just a list of the files referenced in the INCLUDEPICTURE fields. Here is a macro that will do just this:

Sub GetIncludePictures()
    Dim oField As Field
    Dim oCurrentDoc As Document
    Dim oNewDoc As Document
    Dim sFileName As String

    Set oCurrentDoc = ActiveDocument
    Set oNewDoc = Application.Documents.Add

    For Each oField In oCurrentDoc.Fields
        If oField.Type = wdFieldIncludePicture Then
            sFileName = Replace(oField.Code, "INCLUDEPICTURE", "")
            sFileName = Replace(sFileName, "MERGEFORMAT", "")
            sFileName = Replace(sFileName, "\*", "")
            sFileName = Replace(sFileName, "\d", "")
            sFileName = Replace(sFileName, Chr(34), "")
            sFileName = Replace(sFileName, "\\", "\")
            sFileName = Trim(sFileName)
            oNewDoc.Range.InsertAfter sFileName & vbCrLf
        End If
    Next oField

    oNewDoc.Activate

    Set oField = Nothing
    Set oCurrentDoc = Nothing
    Set oNewDoc = Nothing
End Sub

Notice the use of the Replace function several times in the macro. This function replaces occurrences of one string within another string with other text. That may sound confusing, but it is very handy. As an example, imagine that you have a string (sMyString) that contains the characters "This is my string", and that you use the following:

SMyString = Replace(sMyString, "s", "X")

This results in every lowercase "s" in sMyString being replaced with an uppercase "X". The result is that sMyString will now contain "ThiX iX my Xtring".

In the case of the GetIncludePictures macro, the several lines that contain Replace functions work to remove all the extraneous characters from the field code, except for the actual file name of the picture. If you want something else removed, as well, you can add more lines to remove those elements. (For instance, if you wanted to remove a standard path name to where your pictures are stored.)

When the macro is done running, the only thing in the new document should be the name of pictures, as in the following examples:

C:\mypics\picture1.tif
..\graphics\chap01\fig03.gif

If you wanted just the file names, and not the full path names, you could modify the GetIncludePictures macro a bit to include code that parsed out the path. You could do this by adding the following to the macro, just after the line sFileName = Trim(sFileName):

            While Instr(sFileName, "\") > 0
                sFileName = Mid(sFileName, Instr(sFileName, "\") + 1)
            Wend

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 (11777) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Extracting INCLUDEPICTURE File Names.

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

Moving and Copying Cells

At the very heart of editing is the ability to move and copy cells in a worksheet. Understanding the differences between ...

Discover More

Counting Employees in Classes

Excel is very good at counting things, even when those things need to meet specific criteria. This tip shows how you can ...

Discover More

Multiple Taskbar Icons for Documents

If you like to see your open documents in multiple icons on the Taskbar, you may wonder how to make that happen. This is ...

Discover More

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!

More WordTips (ribbon)

Calculating Page Count for a Range of Sections

When adding page numbers to a header or footer, you may find it helpful to modify how Word determines its "Page X of Y" ...

Discover More

Stopping Fields from Updating when Printing

Fields provide a great way to add dynamic content to your documents. If you don't want those fields to update when you ...

Discover More

Converting All DATE Fields to Text

Fields allow you to add a lot of dynamic information to your documents. One field you can add is the DATE field, which ...

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 8 - 5?

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.