Determine if worksheet exists

F

Frank Kabel

Hi
try something like the following

sub test_wks()
dim wks as worksheet
on error goto 0
set wks=activeworkbook.worksheets("ACCOUNTS")
on error goto 0
if wks is nothing then
msgbox "sheet does not exist"
end if
end sub
-----Original Message-----
Hey all,

I'm writing an app that will loop through a series of XLS
sheets and summarize their data. We've provided a temlate
file that our users are supposed to fill in, but they
don't always use it.
The template file contains 2 worksheets, named "ACCOUNTS"
and "TOTALS". The workbooks are locked/protected, so I
have reasonable assurance that those names won't be
changed (nevermind the fact that our user population isn't
savy enough to know how to change the worksheet names if
their lives depended on it).
I'd like to verify that I'm working with the correct WB,
and I think that if I can test for the existence of sheets
named "ACCOUNTS" and "TOTALS", I can do that. Is there an
easy way to do that?
I don't know if it matters, but I'm using Access 2000
automation and referencing Excel objects.
 
F

Frank Kabel

Hi
yes, correct guess :)
-----Original Message-----
I'm guessing that your first "On error GoTo 0" should
have been "On Error Resume Next"....and it works. I
created a UDF for that. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top