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!
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!