Explain use of function property
Public Function bExists(s as String)
for each sh in ActiveWorkbook.worksheets
if lcase(s) = lcase(sh.name) then
bExists = True
exit function
end if
next
bExists = False
End Function
usage
If bExists("sheet1") then
worksheets("sheet1").Printout
else
End if
--
Regards,
Tom Ogilvy
"Freddy" wrote:
My goal is to check for the existence of a worksheet named "Invoice" within
an open workbook. If it exists, then print it. If not, continue with the
existing macro which prints another worksheet tab which will always exist. I
need to know if I can use a function to test whether the "Invoice" worksheet
exists by returning a true or false value, instead of just attempting to
select the worksheet and taking a risk of it not existing then writing error
handling code.
|