Add a check for the error before you go into the loop. IF Directorys = Nothing Or Directorys.Length/Count = -1 Then Error