check if sheet exists

M

mohavv

Hi,

I have a lot of workbooks with same structure which I unprotect with a
macro in personal.xls.
However some have one worksheet less, called "FTE"

How can I test in this macro if a worksheet exists and if so unprotect
it and if not goto next line.

Cheers,

Harold
 
D

Dave Peterson

dim TestWks as worksheet

set testwks = nothing
on error resume next
set testwks = activeworkbook.worksheets("fte")
on error goto 0

if testwks is nothing then
'it ain't there
else
'unprotect it
end if

======
It may be simpler to just ignore the error when you try to unprotect it:

on error resume next
activeworkbook.worksheets("Fte").unprotect password:="hi there"
 

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