Export and link all images in a Word document

G

greenux

Hello,
i have a big problem concerning images in word and hoped that there is
a pro out there who can help me with a small vba script. I have a lot
of Word files with embedded images. These images should be replace by
linked images meaning export all images to a folder an link them by
using the field {INCLUDEPICTURE "image001.jpg" \d}. I'm not as good as
i need to be in VBA to find the images, export them an create a field.
So I hope someone can help me with that. I would be very grateful!
Thanks in advance!

greenux
 
M

macropod

Hi greenux,

The basic problem you're going to have with this is that Word does not retain the original image name in a way that's accessible to
vba - at least not while the document is in the doc format. If you save a document in the RTF format, you can find the original
image names (eg by opening the file as a text stream and searching through it for ".jpg", for example, and then back-tracking from
there to find the 'name' part of each jpg file), but that still may not be enough to tell you which particular image in the Word
document that name relates to. Moreover, it isn't enough to tell you whether the image had been cropped etc in Word or where, if
it's not 'in-line with text', the image's position was on the page concerned. All these details could be gleaned from the Word
document itself, though.

For docx and docm files, I suppose one might be able to search through the relevant xml files for the filenames, but I haven't
explored that.
 
M

macropod

Hi greenux,

Perhaps I misread your post -

If you first save the document as an HTML file, Word will create for you a folder containing all he images. These will be named
'image001.jpg' etc. You might want to maximize the HTML image resolution beforehand, though, to ensure it's good enough for a
printed output. You could then copy these files to your original document's folder and delete the HTML document with its folders.
These processes can be automated with vba.

From there, it's largely a matter of iterating through all images in the document and replacing them with INCLUDEPICTURE fields
pointing to the correct image. This will still be the tricky part - I'm not sure what order Word gives to files in the HTML save
process when it comes to images in headers & footers, tables, and images that aren't in-line. You'd probably want to do a manual
check to verify what happens and emulate the same replacement sequence in your document.

OK, that's the theory. See how you go with coding it. If you run into problems, post back.

An alternative - especially if its a once-off exercise - is to do it manually. It's easy enough to do the above save and then to
create a single INCLUDETEXT field with everything in it and then simply copy & paste the field to each other location where it's
needed then edit the field's image name. If you toggle the field code display 'on' (eg via Alt-F9), that makes it relatively easy to
do this part.
 
G

greenux

Hi marcopod,
thanks for the hints. The main problem with most time effort is
replacing image with the right link field. When exporting to htm all
drawings are also exported to images so there is a order algorithm
which results I can't predict.
So I can't just replace all image by "imageNNN.jpg" where NNN is a
counted value.
Damn it, this means doing everything manually :-(

greenux
 
M

macropod

Hi greenux,
Damn it, this means doing everything manually :-(
Possibly so but, as I said, it's largely a case of copying & pasting the first INCLUDEPICTURE, then editing the filename.

BTW, unless each of your Word files is going to be stored in its own folder, you'll either need to uniquely name each image file or
use the full filepath (which Word inserts behind the scenes in its metacode anyway) in the INCLUDEPICTURE field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top