Open and Activate Outlook via VBScript
<p>I'm using VBS to control a process wherein I need to open Outlook and activate/set focus on the window. I'm running into issues with setting the focus on the window - when it runs, the window focus remains on the Explorer window I had open to double-click and run on the VBS file.</p>

<p>From what I've read, opening a new Outlook instance should take the focus, and if I run the script without having focus on the Explorer window (such as using Sendkeys) it works perfectly fine, but it does not work if the Explorer window has focus. This is important as it will be set through Task Scheduler to run, and so it needs to work no matter where the current focus is when the task runs.</p>

<p>Here's the existing VBS:</p>

<pre><code>Option Explicit

OpenOutlook

Sub OpenOutlook()

  Dim oApp
  Dim oName
  Dim oFolder
  Dim WShell

  Set WShell = WScript.CreateObject("Wscript.Shell")
  Set oApp = CreateObject("Outlook.Application") 
  Set oName = oApp.GetNamespace("MAPI")
  OName.Logon "Default Outlook Profile",, False, True
  Set oFolder = oName.GetDefaultFolder(6)
  oFolder.Display
  OApp.ActiveExplorer.Activate
  WShell.AppActivate "Inbox - myemail@mydomain.com - Microsoft Outlook"

End Sub
</code></pre>