View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Alastair[_2_] Alastair[_2_] is offline
external usenet poster
 
Posts: 1
Default Use of "On Error" within a loop

Hi
I am using the following code (abbreviated) to extract data from daily
statistics files. For various reasons we may not get a file for every
day of the month. It works when all files exist, or when one stats
file is missing. If two files are missing then I get an "Error 1004
.... file could not be found" message when attempting to open the
second missing file.

For i = 1 To 31
On Error GoTo NoBook
Workbooks.Open Filename:="stats_day" & i & ".csv"
'
'process data from the opened workbook
'
NoBook:
Next i

I'm sure there will be a simple explanation, but I am stummped.

Thanks for your help
Alastair