# Word: How to replace images and rename them in VBA



## mesp9942 (May 20, 2013)

Hi,
I have a word document with images in it and using microsoft word VBA I want to go through the document, name each image, and move these images to a folder. I have tried inlineobjects, but this does not include each image on my page. The only way I have been able to extract them is by saving the doc as a webpage, but I am not able to delete or rename the images this way.
Please help.


----------



## SydneyGeek (May 21, 2013)

The easiest way to process a set of images in Word is to place them in bookmarks, and loop through the collection of bookmarks.
This article isn't quite what you want but it shows how to loop through the bookmarks, in this case replacing them with pictures from Excel: Update a Word file by pulling Excel data into bookmarks -- DataWright Information Services

Denis


----------



## Macropod (May 21, 2013)

Cross-posted at: word macro to rename and replace images - VBA Express Forum
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters


----------



## mesp9942 (May 21, 2013)

SydneyGeek said:


> The easiest way to process a set of images in Word is to place them in bookmarks, and loop through the collection of bookmarks.
> This article isn't quite what you want but it shows how to loop through the bookmarks, in this case replacing them with pictures from Excel: Update a Word file by pulling Excel data into bookmarks -- DataWright Information Services
> 
> Denis



The problem is I need all of my images to be put into a bookmark in order to replace them with strings. The only strategy for selecting the images and placing them in bookmarks I have found is selecting them as inlineobjects or inlineshapes and then moving them to a bookmark. My problem is that inlineshapes does not consider all of my images that have been extracted by converting the document to html(webpage). I need all of my images to be put into a bookmark in order to process through them-how can I do this?? If I select them from a saved folder path, they will not be replaced in the location needed on my word doc...
-Meghan


----------



## SydneyGeek (May 21, 2013)

One approach would be to create the bookmarks manually -- see Add or delete bookmarks - Word - Office.com
Then create a 2-column table (you could use the Excel example) with bookmark names in the first, and the full path to your images in the second, and use that code to repopulate the bookmarks.

Denis


----------



## mesp9942 (May 22, 2013)

SydneyGeek said:


> One approach would be to create the bookmarks manually -- see Add or delete bookmarks - Word - Office.com
> Then create a 2-column table (you could use the Excel example) with bookmark names in the first, and the full path to your images in the second, and use that code to repopulate the bookmarks.
> 
> Denis



My problem is I would want to quickly assign a bookmark to each image with a macro all at once, or create a loop to assign each image to a bookmark. Manually would take too much time. I do not know how to identify all images in a doc to assign them to a bookmark, which is the issue here.


----------

