Find name of picture in word

In my post yesterday, I showed three ways of extracting file name information if it was entered in the Alt Text properties of the image. However, file names/file paths don’t automatically populate the Alt Text description field, except under some circumstances. In my testing:

  • if I dragged a saved image from Windows Explorer into Word 2010, the file path and name was added to the Alt Text description field automatically (NOTE: Dragging from Explorer did NOT add the file path/name information in Word 2016 [and possibly in Word 2013]! It seems Microsoft changed this function after Word 2010 for at least one of these reasons: large corporate clients didn’t want file paths visible to readers with the knowledge to find out what they were, or, putting the file path in Alt Text actually went against accessibility guidelines, because a screen reader would read the file path NOT a considered description of what the image was about.)
  • if I dragged a saved image from SnagIt Editor, the file path and name was added to the Alt Text description field automatically
  • if I clicked Insert > Picture in Word, selected an image, then clicked Insert, none of the file information was carried across
  • if I clicked Insert > Picture in Word, selected an image, then clicked the drop-down arrow next to Insert and then selected Insert and Link, the file path/name information is stored in Word, but NOT under Alt Text—you can only find it by going to File > Info, then clicking Edit Links to Files (bottom right of that Info window), then scrolling through the list of links to find those for images. Click the item in the list and the file path/name is displayed in the Source information section. You can’t select it to copy it.

An alternative way to find these file names (whether detailed in Alt Text or not) is to save the Word document as an XML file, then open the XML file in an HTML editing program (you can use a program like Notepad, but you have to find them one at a time for each image file extension [e.g. .gif, .jpg, .jpeg, .png, .emf, .svg, .bmp, .tif, .tiff, etc.]). Ignore any found with paths/names like /media/image1.png etc. as these are the automatically created image files when you saved as XML—they are not the original final names. When you find a legitimate file path/name, copy it to another document. Yes, this is tedious, and there is a marginally quicker way if you have an HTML editing program installed and have a lot of image file names to deal with.

NOTE: You will never get the file name/path for anything inserted using Insert > Picture without linking.

I had Microsoft Expression Web installed on my computer so I used that—it allows you to search for all instances of a term (in my case, a file extension) and lists them in a Results pane. From there, you select them all, then copy the list and paste it into Excel. Once in Excel, you can delete the columns you don’t need and do find/replace to clean up the XML coding you don’t want. Hopefully, you’ll get enough file names to make this a worthwhile exercise.

Here are the steps I used with Expression Web:

  1. Open a new Excel document.
  2. Open the Word document, then save it as an XML file (File > Save As, select Word XML document (*.xml) as the file type). Close the Word document.
  3. Go to (Windows) Explorer, right-click on the XML file you saved in Step 2, then choose the program to open it—in my case, I opened it with Microsoft Expression Web 2.0, and the rest of these instructions are for that program.
  4. Go to Edit > Find, then enter the search term for an image format file extension (the most common ones are .gif, .jpg, .jpeg, .png, .emf, .svg, .bmp, .tif, and .tiff). You can make this quicker by entering .jp to find both jpg and jpeg formats, or .ti to find both .tif and .tiff formats.
  5. Click Find All.
  6. The Results list below the main window shows all lines where the search term was found. Click in the Results list, then press Ctrl+a to select all results.
  7. Right-click on the selected results, then choose Copy Results (Note: Ctrl+c will NOT copy them).
  8. Go to your blank Excel document, and paste the copied results into Excel.
  9. Repeat Steps 4 to 8 for all the other image file formats.
  10. When you have finished finding them all and putting them into the Excel document, save the Excel file.
  11. Now it’s time to clean up the Excel file:
    • delete any columns you don’t need (I only needed the Matched Text column, so I deleted the others)
    • delete any rows you don’t need (those with /word/media/image1.png or /media/image1.png in them—these are the auto generated file names created when you save the Word document as XML)
    • delete any duplicates
    • if you see patterns in the XML code, do several find/replace runs on the file to get rid of the unwanted XML code (e.g. find <wp:cNvGraphicFramePr><a:graphicFrameLocks noChangeAspect=”1″… and replace with nothing)
    • manually delete any remaining XML code that you can’t delete easily with find/replace
  12. Once you’ve cleaned it up, your Excel file should list all the found file paths/names. Sort the list alphabetically so you can identify and delete any further duplicates. (Note: Some images may be listed twice — just the file name and another with the full file path.)

[Links last checked August 2018]

RRS feed

  • Remove From My Forums
  • Question

  • If I insert a picture into a word doc, does it track the name of the inserted file in any way? If so, how can I access that from VBA. Thanks!

All replies

  • Hi Michael,

    I’m afraid it would be impossible to know a file name of inserted picture in Word document.
    I’d like to know why you want to know the file name after inserting a picture. Could you explain it? If they know the reason, they might give an answer or alternative.
    ___________
    Ashidacchi

    • Edited by

      Thursday, June 8, 2017 2:22 AM

  • You can try AlternativeText property of Shape Object

    But note user can change that manually. Although chance is less


    Best Regards,
    Asadulla Javed,
    Jadavpore & Asansol

    • Edited by
      Asadulla JavedEditor
      Thursday, June 8, 2017 9:10 AM
      Update

  • Hi Asadulla Javed,

    I didn’t know AlternativeText property of Shape Object.
    So, I’ve tried to display AlternativeText, but it showed nothing (no text).

    After clicking the button [Find Shape]
        

        
    Here’s code in the button [Find Shape]

    Private Sub btn_FindShape_Click()
        Dim cnt As Integer
        Dim shp As Shape
        cnt = 0
        For Each shp In ThisDocument.Shapes
            cnt = cnt + 1
            MsgBox "count=" & cnt & Chr(13) _
                    & "Shape: Name=" & shp.Name & Chr(13) _
                    & "Alternative Text=" & shp.AlternativeText
        Next
    End Sub

    Can you show/get AlternativeText of a shape object?
    _______________
    Ashidacchi

    • Edited by
      Ashidacchi
      Thursday, June 8, 2017 9:55 AM

  • I did this  long time ago so I don’t have the code.  But I set the Alternative Text with the file name when I inserted the image.  I was able to later query the Alternative Text.

  • If you insert picture from external file then excel automatically sets alternative text with filename of Pic.

    It is writable so user can change the property. Then it can’t help. But most of the cases, user does not care to change it.

    In your case did you insert the shapes from external file ? OP specified that he wants to get filename of inserted shape.


    Best Regards,
    Asadulla Javed,
    Jadavpore & Asansol

  • I’m in Word not Excel, but this is what I’m looking for:                   

    If you insert picture from external file then excel automatically sets alternative text with filename of Pic.

    I inserted about 250 images from external sources. I now want to go through the doc and replace each image with its filename, in preparation for conversion to markdown.

  • Hi Michael,

    Please try to make code by reference to my code showed before.
    In Excel 2016 I could get file name of inserted pictures, but in Word 2016 I could not.

    Private Sub btn_FindShape_Click()
        Dim cnt As Integer
        Dim shp As Shape
        cnt = 0
        For Each shp In ThisDocument.Shapes
            cnt = cnt + 1
            MsgBox "count=" & cnt & Chr(13) _
                    & "Shape: Name=" & shp.Name & Chr(13) _
                    & "Alternative Text=" & shp.AlternativeText
        Next
    End Sub

    _______________
    Ashidacchi

    • Edited by
      Ashidacchi
      Thursday, June 8, 2017 10:37 PM

  • @Ashidacchi — for some reason, I couldn’t get the code to return anything for ThisDocument.Shapes, but I could for InlineShapes, and I got the same result, i.e. nothing for alt text. When I look at the Open XML for the file, the image name and filename
    are both there:

    <wp:docPr name=»Picture 1» id=»1″/>

    . . .

    <pic:nvPicPr>
        <pic:cNvPr name=»Screenshot (1).png» id=»1″/>
        <pic:cNvPicPr/>
    </pic:nvPicPr>

    Screenshot (1).png is the actual filename, so I hope there’s some way to get this from VBA.

  • Hi Michael,

    What type did you Save As?

    _____________
    Ashidacchi

  • Hi Michael, 

    I’m having the same problem. Could you resolve this issue?

    https://stackoverflow.com/questions/64011161/vba-word-find-shape-picture-by-file-name

    Thank you

  • #1

Подскажите, други, как узнать исходное имя файла с изображением, помещенным в Word? И возможно ли это в принципе?

JAW


  • #2

Ответ: Как узнать исходное имя файла с изображением, помещенным в Word?

Если изображение прилинкованно, то Shift+F9 на самом изображении.
Если внедрено, то невозможно.

  • #3

Ответ: Как узнать исходное имя файла с изображением, помещенным в Word?

Если изображение прилинкованно, то Shift+F9 на самом изображении.
Если внедрено, то невозможно.

Думаю, внедрены. Shift+F9 не срабатывает. (А как осуществляется линкование в Ворде?)
Пока решил задачу так. Сохранил как веб-страницу, при этом в отдельную папку сложились и оригинальные изображения — байт в байт. Имена потерялись, но для поставленной цели это не проблема.

suntory


  • #4

Ответ: Как узнать исходное имя файла с изображением, помещенным в Word?

http://www.pcreview.co.uk/forums/do-find-name-picture-file-inserted-word-t2393044.html

If you activate the script editor (ALT+SHIFT+F11), each inserted picture has a reference in the html file displayed that looks like:
<v:imagedata src=»Document4_files/image001.jpg» o:title=»IMG_0255_1_3″/>
where image001.jpg is the new name for the image and IMG_0255_1_3 is the original filename without the extension.

suntory


  • #5

Ответ: Как узнать исходное имя файла с изображением, помещенным в Word?

Сохранил как веб-страницу, при этом в отдельную папку сложились и оригинальные изображения

Если docx, то не надо сохранять в html, это zip архив, картинки в папке media лежат.

  • #6

Ответ: Как узнать исходное имя файла с изображением, помещенным в Word?

За предыдущую ссылку спасибо. Таким способом проверил и понял, что оригинальные названия переименовывались, потому узнать то, что мне хотелось, у меня и не получилось бы.

Если docx, то не надо сохранять в html, это zip архив, картинки в папке media лежат.

Docx не используется ни автором вордовского документа, ни мною.

suntory


  • #7

Ответ: Как узнать исходное имя файла с изображением, помещенным в Word?

Достаточно просто пересохранить в docx и взять картинки, потом можно не использовать и удалить раз не используется.

JAW


  • #8

Ответ: Как узнать исходное имя файла с изображением, помещенным в Word?

А как осуществляется линкование в Ворде?

Через причинное место, как всё в Microsoft. Там при вставке можно выбрать, линк, вставить и оставить линк или просто вставить.
Если вставлять EPS, то есть шанс протянуть наружу CMYK :)
И по комбинациям F9 есть возможность редактировать линки, что тоже полезно.

  • #9

Ответ: Как узнать исходное имя файла с изображением, помещенным в Word?

Спасибо всем за участие в моем вопросе.

MS Word 2010

  • Change your word file extension from .docx to .zip
  • Go into the .zip archive and open file worddocument.xml with any text editor.

  • Look for any text that was close to the image in question an somewhere around you should see XML code similar to
    <pic:cNvPr id=»0″ name=»Test image.png»/>
  • In this case Test image.png was the name of the original image
    MS Word document.xml

MS Word 2010

No thoughts on “Find original file name of inserted image in MS Word 2010”

Using Excel VBA, I need to get the name of a picture in the Active Word document.

This is the code I’m using:

Dim WordApp As Object
Dim DocumentoDestino As Object
Set DocumentoDestino = WordApp.ActiveDocument    
MsgBox DocumentoDestino.Shapes(1).Name

And also:

Dim WordApp As Object
Dim DocumentoDestino As Object
Set DocumentoDestino = WordApp.ActiveDocument    
MsgBox DocumentoDestino.InlineShapes(1).Name

But none of these are working.

The error message is «438: Object doesn't support this property or method«.

asked Apr 24, 2017 at 11:53

10

You need to create the WordApp object first.

Dim WordApp As Word.Application
Dim DocumentoDestino As Document

Set WordApp = CreateObject("word.Application")
Set DocumentoDestino = WordApp.ActiveDocument

answered Apr 24, 2017 at 12:03

Variatus's user avatar

VariatusVariatus

14.3k2 gold badges14 silver badges30 bronze badges

3

Понравилась статья? Поделить с друзьями:
  • Find multiple words in word
  • Find more words from one word
  • Find mode in excel
  • Find microsoft word on my computer
  • Find media words in the word