Search This Blog

Monday 21 November 2016

Close Outlook Email Windows

After a busy day you may find your windows taskbar filled with many applications. Especially if, like me you find it easier not to group the labels by application. You may already have a batch file to kill all internet explorer windows, folders etc. But what about all those emails you have opened? You could close outlook and reopen. But the time it takes to reopen you might as well have gone into outlook and clicked the close all items button. The below script makes use of the 'Close all Items' button and can be tied into a bigger script to close all unnecessary windows. The script uses powershell but can be called from a BAT file for ease of execution. $outlook = new-object -com Outlook.Application $namespace = $outlook.GetNamespace("MAPI") $folder = $namespace.GetDefaultFolder("olFolderInbox") $explorer = $folder.GetExplorer() $explorer.Display() $wshell = new-object -com wscript.shell start-sleep -milliseconds 500 $wshell.Sendkeys("%(V)") $wshell.Sendkeys("C") $wshell.Sendkeys("A") $wshell.Sendkeys("%{F4}")