how to check whether Excel window has focus from vba
===

I have some excel vba macros that can take minutes to an hour to run. At the end of the run they do a bunch of sorting. The problem is that if Excel doesn't have the focus (iow, I'm doing something in another window), it has a problem and I have to close excel and reopen it. I'm not sure what the problem is but I know it happens when it tries to run Sort.Apply. Is there anyway I can check whether excel has the focus, and if not, either give it the focus or popup a checkbox?