How do I replace all images in a word document with code? RRS feed

  • Question

  • I have a word document I have saved as a webpage. I want to replace every image that has been extracted and saved in the web page folder with code. I am unsure how to replace the images with code. I have attempted to use inlineshapes to identify the pictures I want to replace with code, but every extracted picture for webpage format is not the same as the inline images recognized. If i cannot replace each web extracted image with code, how can I name each inlineshape and place it into a folder in my documents?

    Monday, May 20, 2013 5:34 PM

All replies

  • Can you clarify what you mean by "replace every image that has been extracted and saved in the web page folder with code"? What is in the Word document after you do this? A placeholder code such as "Picture 1" is that what you mean? Or are you talking about code as meaning program code such as Visual Basic or C# that performs the extract and then a replacement of the image?

    Kind Regards, Rich ...

    Tuesday, May 21, 2013 2:57 AM
  • A placeholder would be left in the page where the image once was, as well as all of the text and graphs. I want to write a macro in word vba to carry out this task.


    Wednesday, May 22, 2013 4:04 PM
  • Hi Meghan

    I've read this at least five times and it's still not clear to me what you want to do...

    If you've saved a Word document as a webpage, then it's no longer a Word document. If you want to manipulate the web page "document" then you have to work with that file, which will basically be a text file with MHTML mark-up.

    This means that, if you really want to use the Word object model, you'd have to force the file to open in Word as "plain text", not allowing Word to convert it back to a Word document. Then your code would have to work with the MHTML mark-up, not with objects.

    In the web page file, there will be mark-up code that points to the graphics files saved externally so that the web page will load them. You'd need to change that mark-up in order to achieve whatever result it is you're looking for.

    Cindy Meister, VSTO/Word MVP, my blog

    Sunday, June 2, 2013 11:27 AM