VBA - Corrupt Excel Load

P

pramsjois123

Hello ,

We have a Excel add-in which extends the functionality required for
our product. So we have our own Implementation of Open, Save, Save As.

While opening the Corrupted Excel File, It was throwing an Error which
we solved by using 'XlCorruptLoad.xlRepairFile'

Set currExl =
objExcelApplication.Workbooks.Open(FileName:=strFileName, _
ReadOnly:=bReadOnly,
CorruptLoad:=XlCorruptLoad.xlRepairFile)

But now the problem comes when we want to save this using
objWorkbook.Save method which is throwing Error 1004. Since the
behaviour of Excel application is to Invoke a "Save as" dialog for
Repaired files, we also want to do the same thing. But there is no
property or any other way to know from the Workbook Object that it is
opened in Repair mode (safe mode). If we get to know from the workbook
object whether it is opened in normal mode or repair mode , then we
can call SaveAs instead of Save on the workbook object.

We solved this by having a Custom document property which indicates
whether it is opened using 'XlCorruptLoad.xlNormaLoad' or
'XlCorruptLoad.xlRepairFile'. The property value is set after
objExcelApplication.Workbooks.Open() succeeds.
Now this scenario where we open the workbook using
objExcelApplication.Workbooks.Open() method is somewhat looks solved.
But the problem is in other scenarios we are using CreateProcess to
create the Excel workbook instance. In this case we donot have the
control over opening of the workbook. So we are not able to give a
solution in the scenarios where CreateProcess() is used for Creating
Excel workbook. Please let us know the solution for this.

Also other scenario of failure is, when we are using objApp.Dialogs
(xlDialogOpen).Show() method , This method throws exception when we
open the Corrupted file.

Rgds/Pramoda Jois
 
J

joel

When you open the repair file what is the window name in excel (should be
same as name of workbook)?

check the string currexl.name using Instr()
 
P

pramsjois123

When you open the repair file what is the window name in excel (should be
same as name of workbook)?

check the string currexl.name using Instr()












- Show quoted text -

Hi Joel,
I will check this. So you mean if the window name is not same as
Workbook name, we assume that the Excel is opened in repair mode?


Rgds/Pramoda Jois
 
J

joel

When you create a new workbook in excel it doesn't have the XLS at the end.
Only when the file is saved does the xls appear. I don't have a corrupt
workbook to run a test. Not sure how to create one. but I remember seeing a
difference in the window name indicating an error has occured.
 

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