I'm using Excel 2003.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
I'm looping through files, opening them, and writing info into another Excel spreadsheet. I need to check for corrupt excel files. I'm getting close, but I'm getting the error message "this file is not in a recognizable format" and the user would have to remember to select "cancel" (and not "OK"). I'd like to suppress this error message.
<o> </o>
My code:
<o> </o>
In my sub:
<o> </o>
Global FileIsCorrupt as boolean
Global NewFileToCheck as string
Global FileName as string
Global Path as string
<o> </o>
(Filename and path are set at this point...)
<o> </o>
OpenFileAndCheck 'call function
<o> </o>
If FileIsCorrupt = True then 'if true, file is corrupt or unrecognizable
msgbox ("msg to user that it is corrupt and file is being skipped')
GoTo FoundCorruptFile ' skips over writing info from file
End if
<o> </o>
=====
Function OpenFileAndCheck() as Boolean
On Error GoTo ErrHandler
FileIsCorrupt = False 'set to false--it will be reset to true if file is corrupt
Set NewFileToCheck = Workbooks.Open(Filename:=Path & FileName)
<o> </o>
Exit Function
<o> </o>
ErrHandler:
If Err <> 0 then
FileIsCorrupt = True
End if
<o> </o>
End Function
=====
<o> </o>
Your help would be so appreciated!
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
I'm looping through files, opening them, and writing info into another Excel spreadsheet. I need to check for corrupt excel files. I'm getting close, but I'm getting the error message "this file is not in a recognizable format" and the user would have to remember to select "cancel" (and not "OK"). I'd like to suppress this error message.
<o> </o>
My code:
<o> </o>
In my sub:
<o> </o>
Global FileIsCorrupt as boolean
Global NewFileToCheck as string
Global FileName as string
Global Path as string
<o> </o>
(Filename and path are set at this point...)
<o> </o>
OpenFileAndCheck 'call function
<o> </o>
If FileIsCorrupt = True then 'if true, file is corrupt or unrecognizable
msgbox ("msg to user that it is corrupt and file is being skipped')
GoTo FoundCorruptFile ' skips over writing info from file
End if
<o> </o>
=====
Function OpenFileAndCheck() as Boolean
On Error GoTo ErrHandler
FileIsCorrupt = False 'set to false--it will be reset to true if file is corrupt
Set NewFileToCheck = Workbooks.Open(Filename:=Path & FileName)
<o> </o>
Exit Function
<o> </o>
ErrHandler:
If Err <> 0 then
FileIsCorrupt = True
End if
<o> </o>
End Function
=====
<o> </o>
Your help would be so appreciated!