rossbritton26

New Member
Joined
Jul 28, 2011
Messages
33
Hi,

I have some code with opens a file one at a time from a list and this works fine until the file in the list cannot be found in the already specified location.

My only problem is what the code does when the file cannot be found.
Currently, Excel displays a error message and then gives me the option to End or Debug, however as the list of files can be quite large I would just like to skip to "Next k" and resume running the code as if nothing as happened.

I have tried many combinations of onerror etc. but can't seem to crack it,

any ideas?
Ross.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Maybe like this

Code:
On Error Resume Next
'
'try to open the file
'
On Error GoTo 0
 
Upvote 0
OnError Resume Next would be my choice, but without seeing the code I couldnt say it would work for sure
 
Upvote 0
It would be better to test for its existence before trying to open it:
Code:
If Dir("your file path") <> "" Then
' process file code here
End If

for example.
 
Upvote 0
Rory,

That worked brilliantly thank you very much.

I have also implemented the other answers thank you and will use them again in the future. :)

Ross
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top