In today’s article, we will provide you with 2 quick ways to extract all the MS office files embedded in your Word document.
Every so often, we could inherit a Word document containing multiple embedded files, such as below:
Normally, to export them, we will have to open the file and then save it. This way, however, is acceptable when there are few files. Once a large number of objects are involved, we shall look for some more quick and energy-saving shortcuts. For this reason, we have the following 2 methods ready for you.
Method 1: Change the File Extension
- First off, before anything else, we recommend you to make a copy of the target file, in case any incidents may cause damage to it.
- Secondly, right click on the document icon and choose “Rename” on the menu.
- Thirdly, change the extension “.docx” to “.zip”.
- You will encounter with the warning message, and just click “Yes”.
- After the document converting to a zip file, double click to open it.
- Now double click to open “word” folder.
- Then double click to open “embeddings” folder. You can find all files there but without identifiable. The mess is you have to rename them.
Method 2: Run Word Macro
- First and foremost, click on “Developer” tab and then the “Visual Basic”. Or just press “Alt+ F11” instead if the “Developer” tab isn’t available.
- Next click “Normal” project.
- Then click “Insert” tab.
- Choose “Module” on the drop-down menu.
- Now double click on the new module to have the coding space.
- And paste the bellowing codes there:
Sub ExtractAndSaveEmbeddedFiles() Dim objEmbeddedShape As InlineShape Dim strShapeType As String, strEmbeddedDocName As String Dim objEmbeddedDoc As Object With ActiveDocument For Each objEmbeddedShape In .InlineShapes ' Find and open the embedded doc. strShapeType = objEmbeddedShape.OLEFormat.ClassType objEmbeddedShape.OLEFormat.Open ' Initialization Set objEmbeddedDoc = objEmbeddedShape.OLEFormat.Object ' Save embedded files with names as same as those of icon label. strEmbeddedDocName = objEmbeddedShape.OLEFormat.IconLabel objEmbeddedDoc.SaveAs "C:\Users\Public\Documents\New folder\" & strEmbeddedDocName objEmbeddedDoc.Close Set objEmbeddedDoc = Nothing Next objEmbeddedShape End With End Sub
- Finally, click “Run” button or hit “F5”.
All embedded files will be stored under a specific directory with their original names.
Note:
In code line “objEmbeddedDoc.SaveAs “C:\Users\Public\Documents\New folder\” & strEmbeddedDocName”, the “C:\Users\Public\Documents\New folder\” is the location for storing files. Remember to replace it with an actual one.
Take Care of Word Files
Since some of you work with Word very frequently, then confronting with a corrupted Word can be commonplace. Therefore, that’s why we lay much emphasis on well handling files. After all, once a file gets damaged, it takes both time and money to bring it back to life.
Author Introduction:
Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including fixing damaged Excel and pdf repair software products. For more information visit www.datanumen.com
Hurrah, that’s what I was seeking for, what a data! existing here at this blog, thanks admin of this site.
Solution 2 worked fine for me.
81 files extrated in less than 3 minutes.
Thank you Vera Chen and DataNumen, really good job!
Thanks, Method 2 worked fine with JM code.
put On Error Resume Next to the For Each cycle
Sub ExtractAndSaveEmbeddedFiles()
Dim objEmbeddedShape As InlineShape
Dim strShapeType As String, strEmbeddedDocName As String
Dim objEmbeddedDoc As Object
With ActiveDocument
For Each objEmbeddedShape In .InlineShapes
On Error Resume Next
‘ Find and open the embedded doc.
strShapeType = objEmbeddedShape.OLEFormat.ClassType
objEmbeddedShape.OLEFormat.Open
‘ Initialization
Set objEmbeddedDoc = objEmbeddedShape.OLEFormat.Object
‘ Save embedded files with names as same as those of icon label.
strEmbeddedDocName = objEmbeddedShape.OLEFormat.IconLabel
objEmbeddedDoc.SaveAs “C:\Users\Public\Documents\New folder\” & strEmbeddedDocName & “.pdf” ‘Add this extension
objEmbeddedDoc.Close
Set objEmbeddedDoc = Nothing
Next objEmbeddedShape
End With
End Sub
Thank you for the CODE. To make it extract PDF, you need to modify little bit.
Sub ExtractAndSaveEmbeddedFiles()
Dim objEmbeddedShape As InlineShape
Dim strShapeType As String, strEmbeddedDocName As String
Dim objEmbeddedDoc As Object
On Error Resume Next ‘ Add this
With ActiveDocument
For Each objEmbeddedShape In .InlineShapes
‘ Find and open the embedded doc.
strShapeType = objEmbeddedShape.OLEFormat.ClassType
objEmbeddedShape.OLEFormat.Open
‘ Initialization
Set objEmbeddedDoc = objEmbeddedShape.OLEFormat.Object
‘ Save embedded files with names as same as those of icon label.
strEmbeddedDocName = objEmbeddedShape.OLEFormat.IconLabel
objEmbeddedDoc.SaveAs “C:\Users\Public\Documents\New folder\” & strEmbeddedDocName & “.pdf” ‘Add this extension
objEmbeddedDoc.Close
Set objEmbeddedDoc = Nothing
Next objEmbeddedShape
End With
End Sub
The code in the method 2 worked very well for me on one agenda with embedded documents related to each agenda. However, the embedded documents on a different agenda were of a different type, still word documents but which did not get recognize by: ObjEmbeddedShape and thus it does not execute the saveas command. Is thee a different type of embedment?
Martin, from my experience, you cannot extract PDF files – however this will work for Excel files.
The method 1 is better. Save the .doc file with the latest version .docx file and then, change the extension to .zip. So it work for me and it is easy.
Same. I get error 430. Doesn’t work
I get the error “Run-time error ’91’: Object variable or With block variable not set
I’ve tried the Method 2, however, It doesn’t work for me. When I run the macro it returns the error 430: “Class does not support automation or does not supported expected interface.” Is there any solution for that?