Check if the file exists with Dir before trying opening it.
For i = 499 To 598
strTargetFile1 = "D:\Temp\asnout\etASNOutAT156" & i & ".xml"
If Len(Dir(strTargetFile)) > 0 Then
Set wb1 = Workbooks.OpenXML(Filename:=strTargetFile1, LoadOption:=xlXmlLoadImportToList)
Application.DisplayAlerts = False
rownum = rownum + 1
If wb1.Sheets(1).UsedRange.Rows.Count > 1 Then
wb1.Sheets(1).UsedRange.Rows(2).Copy ThisWorkbook.Sheets("Sheet5").Range("A" & rownum)
Else
wb1.Sheets(1).UsedRange.Rows(1).Copy ThisWorkbook.Sheets("Sheet5").Range("A" & rownum)
End If
wb1.Close False
Application.ScreenUpdating = True
End If
Next i
Bookmarks