title: Which Window Is Active
body: <p>I have a short macro that places a cell in edit mode using the command:</p>
  
  <pre><code>Application.SendKeys "{F2}"
  </code></pre>
  
  <p>The line of code runs properly if the macro is run from the worksheet using, say,  the normal Ribbon interface <em>(that is because <kbd>F2</kbd> puts the active cell into Edit Mode)</em></p>
  
  <p>If I run the macro from the <em>VBE</em> window, the macro fails because the <em>VBE</em> interprets <kbd>F2</kbd> to be a command to bring up the Object Browser.</p>
  
  <p>I want to include a test in the macro to check for this:<br></p>
  
  <p>If the worksheet is the active window, proceed running.<br>If the VBE is the active window, then issue a warning MsgBox and abort.</p>
  
  <p>I don't know how to determine which window is active.  <code>ActiveWindow.Caption</code> always displays something like:</p>
  
  <pre><code>Book1.xlsm
  </code></pre>