Re: Skip Corrupt Workbooks In a loop- thanks isn't enough
I included my complete code- besides adding my own code (change the file name based on cell content) I added a whole bunch of on-error-resume lines.
I never paid much attention to error codes because I always created and ran my own macros; if there was an error during test I'd fix it.
This was different, and as I ran the list it would stop with errors after the file opened. I kept putting in the error statments until the errors stopped.
All but one, the I/O device error. Never could surpress that one. So I got a book and a drink and sat there as the macro ran. Every time it beeped, I clicked "No" and it went on its merry way. Yes it took a couple of hours but this is a one time project and it sure beat opening them one at a time.
Thanks again,
michael
Code for the Curious
___________________
Option Explicit
Sub file_opener()
Dim wb As Workbook
Dim wbNames As Range
Dim myfile1 As Range
Dim newname As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wbNames = Range("A1:a34195") 'range of excel filenames
On Error Resume Next
For Each myfile1 In wbNames
Set wb = Workbooks.Open("z:\" & myfile1) 'where the files are
On Error Resume Next
If Not wb Is Nothing Then 'do this if there is an open file
On Error Resume Next
Cells.UnMerge 'won't work if the cell isn't there
'create the new name
newname = Range("a2").Text & Range("c4").Text & Range("h7").Text & Int(Rnd * 100000) 'rnd names the file if all cells are empty
On Error Resume Next
'save the file
wb.SaveAs Filename:="
\\z:\it document\mg1\" & " " & newname & " " & ".xls"
On Error Resume Next
'close the file
wb.Close
On Error Resume Next
End If
On Error Resume Next
Next myfile1 'do it again
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub