How to make inactive when I close application window by Command + W
I'm not sure you can really have both…

Telling Excel to close a window doesn't tell Excel to quit. It doesn't actually tell it anything other than you closed a window. It sits there waiting for you to tell it what to do next; it can't guess what your next action is going to be.

Of course, if you Quit it, then it goes away &amp; the last-used app will be frontmost.

Clicking the desktop is the quickest way to bring the Finder to the front.