title: VBScript set focus on a window in IE
body: <p>I'm updating an old piece of code that uses VBScript to pull up a window in IE.  For some reason, it likes to open up behind IE.  Google gave me the following couple lines for setting window focus in VBScript:</p>
  
  <pre><code>set WshShell = WScript.CreateObject("WScript.Shell")
  WshShell.AppActivate("calculator")
  </code></pre>
  
  <p>However, when I run this in IE, I get the error "Object required: 'WScript'."</p>
  
  <p>Is there any way around this in IE, or another way to do this?  I'm already opening and manipulating a Word document without any problem.</p>
  
  <p>Edit: To clarify, I am running this in a &lt;script type="text/vbscript"&gt; tag in the browser (IE), and the code is crashing on the first line, before I even call AppActivate.</p>
  
  <p><strong>Update</strong>:  My security settings are pretty low; all ActiveX settings are on Enable (this is an intranet service).  I tested the code from <a href="https://stackoverflow.com/questions/2138002/how-to-config-ie-to-make-wscript-shell-work">this</a> question, and the calculator opened without issue.  In fact, I got AppActivate to work with JavaScript, but it's not working with VBScript.</p>
  
  <p>Working JavaScript:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function calcToFrontJ(){
          wshShell = new ActiveXObject("WScript.Shell");
          wshShell.AppActivate("Calculator");
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Not Working VBScript:</p>
  
  <pre><code>&lt;script type="text/vbscript"&gt;
      Public Function calcToFrontV()
          'Set WScript = CreateObject("WScript.Shell") 'breaks with or without this line
          Set WshShell = WScript.CreateObject("WScript.Shell")
          WshShell.AppActivate("Calculator")
      End Function
  &lt;/script&gt;
  </code></pre>
  
  <p>I guess I can always refactor to JavaScript, but I'd really like to know what's going on with this VBScript.</p>
  
  <p><strong>Final Answer:</strong></p>
  
  <pre><code>&lt;script type="text/vbscript"&gt;
      Public Function calcToFrontV()
          'must not use WScript when running within IE 
          Set WshShell = CreateObject("WScript.Shell")
          WshShell.AppActivate("Calculator")
      End Function
  &lt;/script&gt;
  </code></pre>