title: VBScript - Reactivate previous window after using inputbox
body: <p>For my job I often need to enter standard texts in an application to show which actions have been taken.
  At a previous job I have been using a VBScript that I found that worked perfectly. What it does is open up an inputbox, you enter a number and the script runs the corresponding subroutine entering the text you requested.
  Below you can find an example script of how it works.
  In the past I used it in Windows XP, which worked perfectly:</p>
  
  <ul>
  <li>I'm in my application, ready to input text.</li>
  <li>I use a shortcut key to start up the VBScript, say CTRL-ALT-T</li>
  <li>The inputbox opens</li>
  <li>I enter a number</li>
  <li>The inputbox closes and Windows XP automatically goes back to my application</li>
  <li>The text is being put in the application</li>
  </ul>
  
  <p>But Windows 7 has a slightly different task behaviour. When a window closes in W7, the previous window appears on screen but is NOT actively selected. As a result, the text is not being put in that window.</p>
  
  <p>Is there any way to make the window actively selected?</p>
  
  <p>I'm interested in a solution in VBScript form. But if someone happens to know a solution to change Windows 7's behaviour so it behaves like Windows XP concerning this issue, that would be interesting as well. I find the old behaviour much more convenient in general.</p>
  
  <p>Here's a short example of the script:</p>
  
  <pre><code>'-----------------------------
  'VBScript for inputting text
  '-----------------------------
  
  Option Explicit
  Dim oFS, oWS, oWN, Shell
  
  Set oWS = WScript.CreateObject("WScript.Shell")
  Set oWN = WScript.CreateObject("WScript.Network")
  Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
  Set Shell = CreateObject("WScript.Shell")
  '-------
  ' Menu
  '-------
  Select Case InputBox ( _
  "Enter type of comment, then press enter or click Ok..." &amp; vbCrlf &amp; vbCrlf &amp; _
  " [1] Text 1" &amp; vbCrlf &amp; _
  " [2] Text 2", _
  "Menu")
  
  Case "1"
  Call sub1()
  Case "2"
  Call sub2()
  
  Case Else
  WScript.Echo "You entered an invalid menu choice!"
  
  End Select
  
  Call CleanUp
  
  '------------
  ' Subroutines
  '------------
  
  '------------------
  Sub CleanUp()
  Set oWS = Nothing
  Set oWN = Nothing
  Set oFS = Nothing
  WScript.Quit
  End Sub
  
  '------------------
  Sub sub1()
  
  WScript.Sleep 500
  Shell.SendKeys "Standard text 1{ENTER}"
  
  End Sub
  
  '------------------
  Sub sub2()
  
  WScript.Sleep 500
  Shell.SendKeys "Standard text 2{ENTER}"
  
  End Sub
  </code></pre>