batch save graphics (save as graphic) that are embedded in a word document using VBA

Dear Experts:

I got a single 3 column word table in the current word document spanning over several pages. It has the following make-up:

word table 3 columns
I wonder whether a macro could achieve the following actions:

...  Save all the graphics (located in column 3) in the same folder where the current document resides ...
...  with the file names taken from the corresponding article number,
...  i.e the following PNG or JPG files would be created when running the macro:
84-415-30-04.png,
84-415-33-04.png,
84-415-34-04.png

I wonder whether thIs is feasible?

I have attached a sample file for your convenience.

Help is very much appreciated. Thank you very much in advance.

Regards, Andreas

Graphics_to_be_extracted_named.docx
Andreas HermleTeam leaderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
Hi Andreas,
This is somewhere between difficult and impossible in VBA.  You might try saving the document as HTML.  This creates  a subfolder of the format 'Docname_Files'. It contains a file for each graphic, but...

1. The graphics format reflects the original format, in this case .png, .gif or .jpg. You would need a graphics application to convert them to any other format.

2. It might be tricky to match up each file with its image in the document, and hence to choose the correct file name. They are probably in the correct order, but I note that while they are mostly Inline shapes, and least three are Shapes (in the last filled picture cell) . To be sure it might be necessary to analyse the HTML. This is not a five minute job.
Ejgil HedegaardCommented:
You can use Excel to do it.
See attached file.

Use the button "Prepare for new", and all pictures are deleted and cells cleared.

In Word, select all (Ctrl+A), and copy (Ctrl+C).
In Excel, select A1 and paste (Ctrl+V).

Some pictures may be put in wrong, so check, and move to correct location (row).
The top left corner of the picture is the position of the picture.

The pictures are saved in the same folder as the Excel file, so save it.

Then use the button "Save pictures".

The pictures are saved as jpg, with the name in column A.
If more than one picture in a row, the names are added -X001, -X002 etc.
So if files exist, all will be added -XNumber.
Save-pictures.xlsm

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Andreas HermleTeam leaderAuthor Commented:
Hi Graham,

thank you very much for your comprehensive answer. I was suspecting this ...

I know this trick ... saving it as html. I will give this a try with this file although I have tried it several times on other occassions and it was kind of a mess to match everything up. Anyhow, I will check now what Ejgil Hedegaard suggests.

Thank you very much for your great help, Graham, I really appreciate it.

Regards, Andreas
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Andreas HermleTeam leaderAuthor Commented:
Dear Ejgil,

wow, I am truly impressed, great job :-)

I will do some more testing today and then let you know.

Thank you very much for your great support. I really appreciate it.

Regards, Andreas
Andreas HermleTeam leaderAuthor Commented:
Hi Ejgil,

wow, just had a look at the VBA code, really impressive. I was just wondering ... saving as png, would that also be possible?

Andreas
Ejgil HedegaardCommented:
Yes that is possible.
Here is a version for saving as png.
Save-pictures-png.xlsm
Andreas HermleTeam leaderAuthor Commented:
Hi Ejgil,

this is really fantastic, this saves me and/or my colleagues hours and hours of tedious work. I really appreciate your professional expertise.

Thank you very, very much.  :-)

Andreas
Andreas HermleTeam leaderAuthor Commented:
Ejgil: again thank you very much for your superb help, this saves me lots of time :-)

Graham: for the first time  I only award you very few points.  Nevertheless, thank you very much for your insight into this problem, should it be tackled purely with word. for windows.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.