Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching error when opening Excel file with same name

Status
Not open for further replies.

snowmantle

Programmer
Jun 20, 2005
70
GB
Hi,
In VBA if I do

Code:
Workbooks.Open fileName

If the user has a file with the same name already open is there a way to catch the error and ask them to change the selection rather than returning a debug message.. that only lets you end or debug the method?
 



Hi,

BEFORE opening the file, poll the Workbooks Collection to check the name.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Also, some general error handling routine is worth adding in case anything else causes an error so it can be dealt with in a managed way rather than popping up the debug box to the end user.

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top