F
Frank Jones
Workbooks.Open with CorruptLoad parameter set to xlRepairFile fails on Excel
5.0/95 file due to Chart, with Error 1004 Method 'Open' of object
'Workbooks' failed.
We have a sample Excel 5.0 (Excel 95) file that is being opened through a
Visual Basic 6.0 function on Excel 2003 COM call. The Workbooks.Open method
succeededs if CorruptLoad is set to xlNormalLoad, but it fails with Error
1004 if Corrupt Load is set to xlRepairFile.
The Excel 5.0 document has a single sheet with a Chart on it. If the file
is modified such that only the chart is removed, the Open with xlRepairFile
works. If everything else is removed from the file and the Chart remains,
the xlRepairFile Open still fails.
Any ideas on why this might be failing? Is there a limitation of Excel 2003
opening Excel 5.0 file with Charts?
Thanks for any input on this topic.
Function WorkbooksFailSafeOpen(oWorkbooks As Workbooks, strLocalInputFile As
String) As Workbook
Dim lngErrNumber As Long
Dim strErrorDescription As String
On Error Resume Next
Set WorkbooksFailSafeOpen = oWorkbooks.Open(strLocalInputFile, _
UpdateLinks:=2, _
ReadOnly:=True, _
Password:="", _
IgnoreReadOnlyRecommended:=True, _
CorruptLoad:=xlRepairFile)
lngErrNumber = Err.Number
On Error GoTo 0
' If the first open failed with Error 1004
' Method 'Open' of object Workbooks' failed
' Try the alternate Open, without xlRepairFile setting
' Note we can't seem to get the description
' "Method 'Open' of object 'Workbooks' failed"
' out of the Err.Description variable, comes out as
' "Application-defined or object-defined error"
' even though pop-up dialog displays Method 'Open'... message
' so just check against generic error number 1004
If lngErrNumber = 1004 Then
Set WorkbooksFailSafeOpen = oWorkbooks.Open(strLocalInputFile, _
UpdateLinks:=2, _
ReadOnly:=True, _
Password:="", _
IgnoreReadOnlyRecommended:=True, _
CorruptLoad:=xlNormalLoad)
End If
End Function
5.0/95 file due to Chart, with Error 1004 Method 'Open' of object
'Workbooks' failed.
We have a sample Excel 5.0 (Excel 95) file that is being opened through a
Visual Basic 6.0 function on Excel 2003 COM call. The Workbooks.Open method
succeededs if CorruptLoad is set to xlNormalLoad, but it fails with Error
1004 if Corrupt Load is set to xlRepairFile.
The Excel 5.0 document has a single sheet with a Chart on it. If the file
is modified such that only the chart is removed, the Open with xlRepairFile
works. If everything else is removed from the file and the Chart remains,
the xlRepairFile Open still fails.
Any ideas on why this might be failing? Is there a limitation of Excel 2003
opening Excel 5.0 file with Charts?
Thanks for any input on this topic.
Function WorkbooksFailSafeOpen(oWorkbooks As Workbooks, strLocalInputFile As
String) As Workbook
Dim lngErrNumber As Long
Dim strErrorDescription As String
On Error Resume Next
Set WorkbooksFailSafeOpen = oWorkbooks.Open(strLocalInputFile, _
UpdateLinks:=2, _
ReadOnly:=True, _
Password:="", _
IgnoreReadOnlyRecommended:=True, _
CorruptLoad:=xlRepairFile)
lngErrNumber = Err.Number
On Error GoTo 0
' If the first open failed with Error 1004
' Method 'Open' of object Workbooks' failed
' Try the alternate Open, without xlRepairFile setting
' Note we can't seem to get the description
' "Method 'Open' of object 'Workbooks' failed"
' out of the Err.Description variable, comes out as
' "Application-defined or object-defined error"
' even though pop-up dialog displays Method 'Open'... message
' so just check against generic error number 1004
If lngErrNumber = 1004 Then
Set WorkbooksFailSafeOpen = oWorkbooks.Open(strLocalInputFile, _
UpdateLinks:=2, _
ReadOnly:=True, _
Password:="", _
IgnoreReadOnlyRecommended:=True, _
CorruptLoad:=xlNormalLoad)
End If
End Function