Err.Number function

Unimatic1140

New Member
Joined
Jul 18, 2002
Messages
27
Hello everyone, I would like to write an onError/Goto routine that responds differently to two kinds of file errors.

#1 If the macro tries to open a worksheet that doesn't exist, then goto routine#1,

#2 If the macro tries to open a worksheet that another user on the network already has open then goto routine #2, etc.


The problem I’m having is the Err.number function seems to return "1004" for both of these file errors even though they different. Is there a way I can distinguish between an open file and a file that does not exist?

Any help will certainly be appreciated.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi Uni,

I suggest before opening the file (and incurring the error) you first check whether it exists using something like the FileExists method. Then if later you get the error you know it is because it is already open.
 
Upvote 0

Forum statistics

Threads
1,203,614
Messages
6,056,304
Members
444,858
Latest member
ucbphd

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