I have got a rather odd issue. I have over 10,000 .docx files that have a minor corruption in them. When you open the file, Microsoft Word 2010 informs me that "the file *****.docx" cannot be opened because there are problems with the contents.". Once I OK the prompt, it asks if I want to recover the content in *****.docx. Pressing Yes brings up the document contents perfectly. The trouble is, I have to then save/ overwrite the existing file and for 10,000+ files, it is becoming a very time consuming endeavor. I have tried comparing the corrupted file with the de-corrupted file in text editor, but there is nothing obvious there which I can put in a batch script. I tried renaming both to .zip to inspect, but the corrupted file turns into a corrupted zip. Has anyone ever come across this and found a batch solution? I have purchased DiskInternals Word Recovery, however that particular program does not solve the problem.
Any help / advice / direction would be greatly appreciated.
Thanks in advance!
Hi Denis Maybir,
I suggest you record a macro about opening and repairing the file.
There is a sample macro for your reference.
Sub Macro5() ' ' Macro5 Macro ' ' Documents.Open FileName:="20150806.docx", ConfirmConversions:=True, _ ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _ PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _ WritePasswordTemplate:="", Format:=wdOpenFormatAuto, XMLTransform:="", _ OpenAndRepair:=True Windows("Edward.docm").Activate End Sub
You can refer to this article to get more information:
https://msdn.microsoft.com/en-us/library/office/ff835182.aspx
You can also refer to this similar case:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/10b3f42a-76bb-450d-b1d7-77469205471b/macro-to-open-and-repair-word-2003-in-bulk
Hope it's helpful.
Regards,
Emi Zhang
TechNet Community Su
Hi Emi,
Thank you very much. I will try this today if possible and post an update.
Must appreciated!
Regards,
Denis
Emi,
I have managed to make use of the macro function as you advised. I had to first generate a text file containing all the *.doc* files using command prompt:
dir /b /s "C:\Stuff\*docx" > "C:\Users\Denis\Desktop\Testbench\files.txt
I then fed the text file into this macro:
Public Function RepairFile(File As String) ' repairs a single given file Dim doc As Word.Document RemoveReadOnly (File) Set doc = Documents.Open(File, _ AddToRecentFiles:=False, Visible:=False, OpenAndRepair:=True) doc.SaveAs FileName:=File doc.Close End Function Public Function RemoveReadOnly(filePath As String) Dim FSO As Object Dim fil As Object Set FSO = CreateObject("Scripting.FileSystemObject") Set fil = FSO.GetFile(filePath) If fil.Attributes And 1 Then '1 = ReadOnly fil.Attributes = fil.Attributes - 1 End If End Function Sub FixAllMyFiles() Dim FileName, listFile, listLines, objFSO FileName = "C:\Users\Denis\Desktop\Testbench\files.txt" Set objFSO = CreateObject("Scripting.FileSystemObject") listFile = objFSO.OpenTextFile(FileName).ReadAll listLines = Split(listFile, vbCrLf) For Each Line In listLines 'WScript.Echo Line Debug.Print Line RepairFile (Line) Next End Sub
Thank you for your help!
Regards,
Denis