I'm trying to extract all the embedded Excel files in a Word docx. I know that I can do this quickly by changing filename of the docx to zip, and then find all the Excel files in word/embeddings folder.
The problem is that the Excel files in word/embeddings have very generic filenames (e.g., Microsoft_Excel_Macro-Enabled_Worksheet1.xlsm, Microsoft_Excel_Macro-Enabled_Worksheet2.xlsm) instead of the original filename. The original files, however, were actually csv not xlsm files.
I did not play any part in creating this document. I assume they used Insert -> Object -> Create From File. Also, I'm using Word 2010, but according to the Compatibility Checker the document was originally created with Word 97-2003, and the files were embedded later with Word 2007.
I can find the original filename if I go into the docx, right click on embedded file icon, and go to Macro-Enabled Worksheet Object -> Convert... -> Change Icon... -> Caption
However, I don't want to do this manually for a bunch of embedded Excel files.
So is there a way to use some vba code to extract a list of the original filenames for all embedded files? Then I can use this list as a key to rename the generically named files.
VBA
try hitting record button on the lower left corner and record what you need to do. Later come back and edit the code for having loops over the whole document. If you provide a reproducible code by the method above I can help you with the second part. – M--*.zip
. Then open the zip file and navigate todocument.xml.rels
file. Read every line that has.xls
in it and write it into a text file. That's what I would do if I had to. Couple of notes if you decide to go with this option: 1.7zip
can read inside of a zip file. 2. You can find plenty of simple examples here for scripting. – M--document.xml.rels
and it doesn't look like it gives me the Caption info either. It has some Relationship Id instead.Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package" Target="embeddings/Microsoft_Excel_Macro-Enabled_Worksheet68.xlsm"/><Relationship Id="rId324"
– Korean_Of_the_Mountain