Word 2003 Repair corrupt docs per Macro: Save doesn't work

O

ODI

I'm trying to repair a folder full of corrupt documents by using "open and
repair" funktion in my procedure. This works well, but saving the repaired
document does not save the repairs, although the document seems to be changed
in file system.

If I do it manually: I open the document with open&repair and click
"Save"-Button; a warning message appears asking me if I want to save the
repairs in the document. I think this is the problem: how do I pass the
information needed for this warning. I use the parameter SaveChanges to save
them, there should be something else !?

Here is the Code i'm using:
Option Explicit

Public Sub CorruptBatch()

Dim strFileName As String
Dim strFilePath As String
Dim oDoc As Document

' Set Directory for Batch Process
strFilePath = "C:\Test\"

' Get Name of First .doc File from Directory
strFileName = Dir$(strFilePath & "*.doc")


While Len(strFileName) <> 0

' Set Error Handler
On Error Resume Next

' Attempt to Open the Document
Set oDoc = Documents.Open(FileName:=strFilePath & strFileName,
Visible:=True)

Select Case Err.Number
Case 0
' Document was Successfully Opened
Debug.Print strFileName & " was processed."

Case 5151
' Document is corrupt and was NOT Opened
Debug.Print strFileName & " is corrupt " & _
"and will be repaired."
Set oDoc = Documents.Open(FileName:=strFilePath &
strFileName, Visible:=True, OpenAndRepair:=True)
oDoc.Close wdSaveChanges, wdOriginalDocumentFormat
' Clear Error Object and Disable Error Handler
Err.Clear
On Error GoTo 0
' Get Next Document
GoTo GetNextDoc

Case Else
' Another Error Occurred
MsgBox Err.Number & ":" & Err.Description
End Select

' Disable Error Handler
On Error GoTo 0

' Close Document
oDoc.Close

' Clear Object Variable
Set oDoc = Nothing

GetNextDoc:

' Get Next Document from Specified Directory
strFileName = Dir$()

Wend

End Sub

Thanks in advance!
 

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