check this out

http://www.dailydoseofexcel.com/archives/category/vba/

then search int he page for "detect"