In VBA, check if file is corrupt or not Excel

I'm using Excel 2003.

Using VBA, I am looping through a number of excel files, extracting data 
from each, and writing that data into another excel spreadsheet.  

Occasionally, there is a Word document in the directory, and once there was 
a corrupt Excel spreadsheet.

How do I check if the excel file that I'm trying to open is corrupt or not 
in an Excel format?

Your help would be greatly appreciated!
0
Utf
12/17/2009 3:19:02 PM
excel.programming 6508 articles. 2 followers. Follow

5 Replies
2444 Views

Similar Articles

[PageSpeed] 48

Hi laavista

You can loop through only the excel files and if it can't open the file skip it

See
http://www.rondebruin.nl/copy3.htm




-- 

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"laavista" <laavista@discussions.microsoft.com> wrote in message news:944A728C-BD02-49E1-B052-02DD58F84E40@microsoft.com...
> I'm using Excel 2003.
> 
> Using VBA, I am looping through a number of excel files, extracting data 
> from each, and writing that data into another excel spreadsheet.  
> 
> Occasionally, there is a Word document in the directory, and once there was 
> a corrupt Excel spreadsheet.
> 
> How do I check if the excel file that I'm trying to open is corrupt or not 
> in an Excel format?
> 
> Your help would be greatly appreciated!
0
Ron
12/17/2009 8:18:45 PM
I've tried checking for an error code each time I open a file, but the user 
gets an error message from Excel and it stops the program.

Any suggestions?



"Ron de Bruin" wrote:

> Hi laavista
> 
> You can loop through only the excel files and if it can't open the file skip it
> 
> See
> http://www.rondebruin.nl/copy3.htm
> 
> 
> 
> 
> -- 
> 
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
> 
> 
> "laavista" <laavista@discussions.microsoft.com> wrote in message news:944A728C-BD02-49E1-B052-02DD58F84E40@microsoft.com...
> > I'm using Excel 2003.
> > 
> > Using VBA, I am looping through a number of excel files, extracting data 
> > from each, and writing that data into another excel spreadsheet.  
> > 
> > Occasionally, there is a Word document in the directory, and once there was 
> > a corrupt Excel spreadsheet.
> > 
> > How do I check if the excel file that I'm trying to open is corrupt or not 
> > in an Excel format?
> > 
> > Your help would be greatly appreciated!
> .
> 
0
Utf
12/17/2009 9:33:02 PM
More info please

-- 

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"laavista" <laavista@discussions.microsoft.com> wrote in message news:7C014160-6D49-4B70-A9C5-8FCC12246397@microsoft.com...
> I've tried checking for an error code each time I open a file, but the user 
> gets an error message from Excel and it stops the program.
> 
> Any suggestions?
> 
> 
> 
> "Ron de Bruin" wrote:
> 
>> Hi laavista
>> 
>> You can loop through only the excel files and if it can't open the file skip it
>> 
>> See
>> http://www.rondebruin.nl/copy3.htm
>> 
>> 
>> 
>> 
>> -- 
>> 
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>> 
>> 
>> "laavista" <laavista@discussions.microsoft.com> wrote in message news:944A728C-BD02-49E1-B052-02DD58F84E40@microsoft.com...
>> > I'm using Excel 2003.
>> > 
>> > Using VBA, I am looping through a number of excel files, extracting data 
>> > from each, and writing that data into another excel spreadsheet.  
>> > 
>> > Occasionally, there is a Word document in the directory, and once there was 
>> > a corrupt Excel spreadsheet.
>> > 
>> > How do I check if the excel file that I'm trying to open is corrupt or not 
>> > in an Excel format?
>> > 
>> > Your help would be greatly appreciated!
>> .
>>
0
Ron
12/17/2009 10:09:50 PM
Try clicking on Tools/Options... click the General tab on the dialog box 
that appears and note which OptionButton is selected in the Error Trapping 
panel... if it is "Break on All Errors", then that is your problem... change 
the selection to one of the other two (my suggestion is "Break in Class 
Module"... it does the same thing as "Break on Unhandled Errors" plus some 
additional things).

-- 
Rick (MVP - Excel)


"laavista" <laavista@discussions.microsoft.com> wrote in message 
news:7C014160-6D49-4B70-A9C5-8FCC12246397@microsoft.com...
> I've tried checking for an error code each time I open a file, but the 
> user
> gets an error message from Excel and it stops the program.
>
> Any suggestions?
>
>
>
> "Ron de Bruin" wrote:
>
>> Hi laavista
>>
>> You can loop through only the excel files and if it can't open the file 
>> skip it
>>
>> See
>> http://www.rondebruin.nl/copy3.htm
>>
>>
>>
>>
>> -- 
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>>
>> "laavista" <laavista@discussions.microsoft.com> wrote in message 
>> news:944A728C-BD02-49E1-B052-02DD58F84E40@microsoft.com...
>> > I'm using Excel 2003.
>> >
>> > Using VBA, I am looping through a number of excel files, extracting 
>> > data
>> > from each, and writing that data into another excel spreadsheet.
>> >
>> > Occasionally, there is a Word document in the directory, and once there 
>> > was
>> > a corrupt Excel spreadsheet.
>> >
>> > How do I check if the excel file that I'm trying to open is corrupt or 
>> > not
>> > in an Excel format?
>> >
>> > Your help would be greatly appreciated!
>> .
>> 

0
Rick
12/17/2009 10:12:41 PM
On Dec 17, 3:12=A0pm, "Rick Rothstein"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> Try clicking on Tools/Options... click the General tab on the dialog box
> that appears and note which OptionButton is selected in the Error Trappin=
g
> panel... if it is "Break on All Errors", then that is your problem... cha=
nge
> the selection to one of the other two (my suggestion is "Break in Class
> Module"... it does the same thing as "Break on Unhandled Errors" plus som=
e
> additional things).
>
> --
> Rick (MVP - Excel)
>
> "laavista" <laavi...@discussions.microsoft.com> wrote in message
>
> news:7C014160-6D49-4B70-A9C5-8FCC12246397@microsoft.com...
>
>
>
> > I've tried checking for an error code each time I open a file, but the
> > user
> > gets an error message from Excel and it stops the program.
>
> > Any suggestions?
>
> > "Ron de Bruin" wrote:
>
> >> Hi laavista
>
> >> You can loop through only the excel files and if it can't open the fil=
e
> >> skip it
>
> >> See
> >>http://www.rondebruin.nl/copy3.htm
>
> >> --
>
> >> Regards Ron de Bruin
> >>http://www.rondebruin.nl/tips.htm
>
> >> "laavista" <laavi...@discussions.microsoft.com> wrote in message
> >>news:944A728C-BD02-49E1-B052-02DD58F84E40@microsoft.com...
> >> > I'm using Excel 2003.
>
> >> > Using VBA, I am looping through a number of excel files, extracting
> >> > data
> >> > from each, and writing that data into another excel spreadsheet.
>
> >> > Occasionally, there is a Word document in the directory, and once th=
ere
> >> > was
> >> > a corrupt Excel spreadsheet.
>
> >> > How do I check if the excel file that I'm trying to open is corrupt =
or
> >> > not
> >> > in an Excel format?
>
> >> > Your help would be greatly appreciated!
> >> .- Hide quoted text -
>
> - Show quoted text -

I will try this right away.  Thanks!
0
Laavista
12/17/2009 10:35:13 PM
Reply:

Similar Artilces:

VBA code to say Yes or No if any VBA code is present in ActiveWork
Using XL 2003 & 97 Would like hit Ctrl+Shift+V and have an answer either yes or no as to the presence of Any VBA code in the Active Workbook. I do know that about the VBA editor/Explorer or to press the Run Macro button and get a list from various sources . I would like to stay at the keyboard and process a series of macros including one to let me know if I even need to evoke the VBA explorer. TIA Dennis There is no bootstrap macro to tell you whether you have macros or not. If there were there would be no limit to virus writers. --- HTH, David McRitchie, Microsoft MVP - Excel ...

encoding wmv file
hello I have a sample application developed in MFC dialog based project using directx sdk 9. the sample captures video from a webcam and saves it to a wmv file now i have to put that video into streaming server. i beleive that i will have to encode the wmv file using some codecs to put it into streaming server. i want to do the capturing and encoding simultaneously. below is a portion of my code to capture video // capture video pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, // Pin category &MEDIATYPE_Video, // Media type p...

How to Use One PST file on Two Computers?
Hello: I have a desktop machine with a pst file in my Outlook 2003. I would like to copy this pst file to my laptop. How do I synchronize the same file on 2 machines so I won't get duplicate e-mails? I use one premium Yahoo e-mail account and several free Yahoo accounts with YahooPOPs.. Thanks in advance, Spudy Hi Spudy, it is not possible by default to share PST files. A list of a list of third-party synctools are also on this site: http://www.slipstick.com/outlook/sync.htm On the Microsoft Office Marketplace site is a list of third-party messaging tools: http://office.microsoft.com...

Excel separator pages
When printing multiple copies of a spreadsheet if it is set to collate I get multiple separator pages 1 for each copy, if I turn off the collate option, I only get 1 separator page. Can this be adjusted in any way so I don't get multiple separator pages even when I use the default collate option?? ...

File location?
Where are the aspx files stored? http://site/subsite/list/defautl.aspx where would i find that? the reason i ask is when i go to export there are a couple of files that im told access denied. not sure why since im the admin on all levels. Thanks Justin Well, that really depends... mostly your stuff is stored in SQL, which means that its really data in a table cell. However, depending on whether a page has been customized or not it could be pointing to definition files that are stored on the Web Front End servers, and you really want to leave those alone. Furthermore, th...

Print, Merged Cells, and VBA
Hello I'm looking for a code that will help me with a print job for a worksheet. There are a lot of merged cells and a lot of "IF"s to be used in the VBA for range selection. Thanks in advance, Sarr ...

Backup cannot copy .pst files
When I exit Outlook and click on Save Backup. I get the error "Cannot copy Outlook: The process cannot access the file beause another process has locked a portion of the file" Please advise with how to fix this problem. ...

Use VBA to update Access table or Query from Excel
Can I use VBA to update Access table or Query from Excel? Thanks in advance Hi Leungkong, > Can I use VBA to update Access table or Query from Excel? Of course, using ADO or DAO. See: http://www.erlandsendata.no/english/index.php?d=envbadacexportado Regards, Jan Karel Pieterse Excel MVP http://www.jkp-ads.com Hi Jan, Thanks. I think ADO is what I want. But I am not only want to export from excel to access. I want to edit some data in access table. For example, Access has a table "ProductList" I want to use Excel to call the product by "Pro...

Missing DLL file prevents me using PST Files?
Hello - I posted on here a while ago asking for help as following a company merger I cannot use PST files in Outlook 2000 (Windows NT machine). I have been told that work have removed a DLL file which is causing this. Do any of you have experience of this? If so any idea what DLL file I need to add back in? Many thanks, Carl. Do you mean that the corporate IT removed the DLL so you can't use PSTs? Do they have a good reason for this? "Carl Jarvis" <carljarvis@nothankyouforthespammister.co.uk> wrote in message news:1125040515.4863.0@nnrp-t71-03.news.uk.clara.ne...

Reserved names in Excel
Does anybody know a list of predefined names in Excel ? I know names like Print_Area and Print_Titles, but are there more? Regards There's another called FilterDatabase (from data|filter|Autofilter). And probably lots more. Get this name manager by Jan Karel Pieterse's (with Charles Williams and Matthew Henson). You can find it at: NameManager.Zip from http://www.bmsltd.co.uk/mvp Then open this addin and run it against a workbook that you've used a lot. You might see lots of stuff that you never knew about. Hans wrote: > > Does anybody know a list of predefined n...

wav file format
Hello, I am trying to write a *.wav file. I read about its format and now I can write a *.wav file but when I am trying to play it with Media player, it reports that the file is corrupted which I think means that there is a problem on the file format but I couldn't find what is it. Is there any application that could read a wav file and report if there is any problem in its format? Is there any code that helps me to find what I can use to write a wav file? Any help is very appreciated. Best regards Have you seen www.wotsit.org? "ma" <ma@nowhere.com> wrote i...

VBA and Scheduled task in Outlook
Hi, how can I: a) pull the query from somewhere and send it by e-mail automatically. E.g. I want to take a temperature table from http://www.wunderground.com/history/airport/EHAM/2009/7/10/DailyHistory.html?req_city=NA&req_state=NA&req_statename=NA where 2009/7/10 is the date of yesterday put it into an e-mail and send it automatically each day at 8 o'clock? b) if this is not possible, how can I send an e-mail with the attachment c:\Documents\query20090710.xls each day at 8 o'clock? my boss wants this automatized, I know how to write the VBA code for Excel, but don'...

xls file failure
A log.xls file was saved to the desktop in win'98se. On double clicking the file, an 'i' error is generated indicating that the 'file cannot be accessed. The file may be read only.'. The file attribute was archive and changing it to anything else, didn't help. Copy-paste and rename also didn't help. Is this file unrecoverable? Thanks. Len Delete all files in your C:\windows\temp directory -- files and directories that is, reboot and try again "lendapilot" <lendapilot@discussions.microsoft.com> wrote in message news:FE94FAF2-AF35-44B8-91F4-B97...

VLOOKUP in VBA
On the worksheet I can insert in a cell =VLOOKUP(C5, Hobokee.xls!AcsLow, 2) and it works perfectly, looks up the value in column 2 of the range named AcsLow in the same workbook. But elswhere I want in a macro to lookup the same table and assign the result to a variable BalAmt. BalAmt = VLOOKUP(AccNum, Hobokee.xls!AcsLow, 2) does not work. It gives a function not defined error on Hobokee. If instead of Hobokee I put Workbooks("Hobokee"), it gives function not defined error for VLOOKUP which it changes to VLookup. I have been overVLOOKUP in the Help file and see nothing wrong. W...

vba select field
Hi, having a button on a form, is it possible to select only some fields (all from the same table) of the current record instead of all fields? I've tried this code: RunCommand acCmdSelectRecord RunCommand acCmdCopy Forse dipende dei dati nel record. but it selects ALL fields in the form. Thank you. Remigio hi, On 10.04.2010 18:01, remigio wrote: > having a button on a form, is it possible to select only some fields > (all from the same table) of the current record instead of all fields? > I've tried this code: > > RunCommand acCmdSelectRecord &...

Restoring Exchange Store files to a new server
We had a major system crash this week but I was able to grab the entire exchsrv directory from the server. What files do I need to copy to the new server to get all of my exchange mail/public folders/etc loaded on the new server? Thanks, CJ What version of Exchange? -- Ed Crowley MVP - Exchange "Protecting the world from PSTs and brick backups!" "Curious Joe" <joebob.johnson@gmail.com> wrote in message news:1160176822.798021.310710@m73g2000cwd.googlegroups.com... > We had a major system crash this week but I was able to grab the entire > exchsrv director...

Check to see if entire string is UpperCase?
I know I can check if an individual character is uppercase If X Like "[A-Z]" but is there a way to check if a string of indeterminate length is all uppercase? if ucase(myStr) = mystr then 'it looks the same as uppercase But if your string looks like: myStr = "7!@#$_-==--" Then upper/lower case doesn't really make sense. msnyc07 wrote: > > I know I can check if an individual character is uppercase If X Like "[A-Z]" > but is there a way to check if a string of indeterminate length is all > uppercase? -- Dave P...

Check this important pack for Microsoft Internet Explorer
--fmjgxmkqtnv Content-Type: multipart/related; boundary="pgdezubmwcflmod"; type="multipart/alternative" --pgdezubmwcflmod Content-Type: multipart/alternative; boundary="norerrblcyfmfl" --norerrblcyfmfl Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Microsoft Client this is the latest version of security update, the "November 2003, Cumulative Patch" update which fixes all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express as well as three newly discovered vulnerabilities. Install now...

Files Ofiice 2003 using Vista operating system
Where are my pab or pst files in Microsoft Office 2003 when using Micrsoft Vista Home Premium? Or do they have another name or location Hondaman95 <Hondaman95@discussions.microsoft.com> wrote: > Where are my pab or pst files in Microsoft Office 2003 when using > Micrsoft Vista Home Premium? Or do they have another name or location The PAB is obsolete and you shouldn't be using one. The PST's default location is %LocalAppData%\Microsoft\Outlook -- Brian Tillman [MVP-Outlook] "Brian Tillman" wrote: > Hondaman95 <Hondaman95@discussions.microsoft....

Dates in Excel #8
Why does Excel assume that when you type December 2004 that you want the numeric equivalent and not a text entry? Is this just another illustration of Microsoft knowing what we need before we know it? Thanks I don't know why MS assumes this but you can precede the entry with an apostrophe and it will be text -- Regards, Peo Sjoblom "FJB" <FJB0623@aol.com> wrote in message news:1109089977.316088.311020@g14g2000cwa.googlegroups.com... > Why does Excel assume that when you type December 2004 that you want > the numeric equivalent and not a text entry? Is this jus...

Printing a merged to file
Hello, I have searched for this topic but did not find another similar question. I am merging mail addresses to a four up postcard form. If I merge to a document and try to print it, I either get four copies of the same address on each sheet or one copy in the middle of the four up form. If I merge to the printer, I get four addresses per sheet in the right place. That would be fine, but some of the addresses are long enough that they wrap and they wrap in a place where the program decides. Foe example: Johnathan Quixley & Jane Elizabeth Doe may wrap to be "Johnathan Quixley & J...

Excel VBA/Macro programming for beginners
Hi all, I know a bit VB 6.0 programming. Will it help me to write exce vba/macro(same thing?).can anybody help me by providing some fre websites where i can have informations/codes for VBA/macro. Please tell me how could i make a *command Button * in a cell in th excel sheet -- sdebu_200 ----------------------------------------------------------------------- sdebu_2000's Profile: http://www.officehelp.in/member.php?userid=430 View this thread: http://www.officehelp.in/showthread.php?t=118812 Posted from - http://www.officehelp.i Try David McRitchie's "getting started with mac...

Turn pc speaker on/off with vba code
Is this possible? Thanks I found something here on how to do it withVBScript. You can probably modify it to work in VBA http://www.pcreview.co.uk/forums/thread-1468591.php -- HTH, Barb Reinhardt "David" wrote: > Is this possible? > Thanks Thanks Barb I'll have a go (I need to improve my web searching skills) "Barb Reinhardt" wrote: > I found something here on how to do it withVBScript. You can probably modify > it to work in VBA > > http://www.pcreview.co.uk/forums/thread-1468591.php > -- > HTH, > ...

Check for File Open
Is there some way (in VBA) to check to see if a file (spreadsheet) is in use before you try to open it? -- Bill @ UAMS Ivan F Moala posted this (I didn't try it): Yes you can do this programtically. Have a look here for how to determine if a workbook is Open and by Who. http://www.xcelfiles.com/IsFileOpen.html and MS has a version: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q138621 XL: Macro Code to Check Whether a File Is Already Open (Q138621) And it's even called "IsFileOpen" BillCPA wrote: > > Is there some way (in VBA) to check to see if ...

File> ... Can I see more file names?
When I click on File I see (below the list of available options) four previously saved xls files. How do I see more , say the last 10 saved files? <Tools> <Options> <General> tab, And increase to 9 (max) the number of entries in the "Recently Used File box. -- HTH, RD ============================================== Please keep all correspondence within the Group, so all may benefit! ============================================== "SouthAfricanStan" <me@there> wrote in message news:uAdxTx8FFHA.1260@TK2MSFTNGP12.phx.gbl... When I click on File I see...