VBA, unreadable file blocking loop through directory

  • (also posted at http://stackoverflow.com/quest…ng-loop-through-directory)


    Hi guys,
    one of my files when looping through directory is causing my loop to stop. Anyway I can bypass/include these types of files?



    I get the excel found unreadable content error message when opening this file on its own. So is there anyway I can bypass these kind of files(ones with 'unreadable content') and perhaps list them in an error message?


    Any help would be greatly appreciated.
    Here is my full code:



  • Re: VBA, unreadable file blocking loop through directory


    Hi,


    you can use

    Code
    ON ERROR RESUME NEXT

    if you want VBA to skip any error and to trap it back, use

    Code
    ON ERROR GOTO 0


    Example

    Code
    ON ERROR RESUME NEXT
    
    
    Sheets("Sheet100").select
    
    
    ON ERROR GOTO 0


    Cheers

  • Re: VBA, unreadable file blocking loop through directory


    Quote

    Post from other forum has been deleted.


    Well then you have posted on more than one site, because I'm still looking at it. Please update your post to include all links to where you have posted this question as soon as reasonably possible.

  • Re: VBA, unreadable file blocking loop through directory


    As you can't edit your original post (over 24 hours) I'll update it with the post that I am aware of. If there are more then you need to inform us immediately.


    Cross-posting without a link is against the rules that you agreed to upon joining and is taken very seriously due to the efforts and time it wastes for those who kindly volunteer their resources. This is a final reminder, please familiarise yourself with the forum rules to ensure it doesn't happen again.

  • Re: VBA, unreadable file blocking loop through directory


    thanks, this was post i was saying i deleted. but questions still show if you delete on that site.

  • Re: VBA, unreadable file blocking loop through directory


    Quote

    but questions still show if you delete on that site.


    .....they don't. I've been on there for a while (you may have noticed I've actually edited your question) - If you press the 'delete' link under your question you verify the request and it goes.


    That being said this is all straying away from the scope of this thread/question and so I'll leave it here.

  • Re: VBA, unreadable file blocking loop through directory


    You could try specifying a value for the CorruptLoad parameter of the FileOpen method:

    Code
    Set r = Workbooks.Open(CorruptLoad:=xlRepairFile, Filename:="C:\User\Name\documents\demo.xls")


    But you really should include ormat error handling as well.

  • Re: VBA, unreadable file blocking loop through directory


    Quote from Grimes0332;756850

    You could try specifying a value for the CorruptLoad parameter of the FileOpen method:

    Code
    Set r = Workbooks.Open(CorruptLoad:=xlRepairFile, Filename:="C:\User\Name\documents\demo.xls")


    But you really should include ormat error handling as well.



    Hi Grimes, good point. But I ended up figuring out to use On Error Resume next. Now Im just troubled with compiling these file names into a new sheet within the workbook.

  • Re: VBA, unreadable file blocking loop through directory


    You don't use 'On Error Resume Next' to simply ignore errors - you'll just cause more problems for yourself.


    You should handle errors correctly (The 'include ormat error handling' above should have read 'include formal error handling' so apologies if that was not clear). The added bonus is when you do trap and handle the errors you know exactly which workbook caused the error.


    Go and google for "pearson vba error handling", then read and understand the page by Chip Pearson (most likely will be the first result) then you can deal with issues like this easily.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!