Link to home
Start Free TrialLog in
Avatar of ddantes
ddantesFlag for United States of America

asked on

VBS to open outlook.exe and perform send/receive

Running Outlook 2007 on a Windows 7 platform, I would like a VBS script which will open Ouitlook, perform a send/receive, and close Outlook.   I plan to use this VBS in association with a POP Email checker, so that messages will be automatically downloaded if a message with specific criteria is found on the server.

The following code will open Outlook, but I need help with coding the send/receive and then closing Outlook...

Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.run "Outlook"
If Err <> 0 then
Err.Clear
Set ObjOL= CreateObject("Outlook.Application")
End If
SOLUTION
Avatar of Imtiaz Hasham
Imtiaz Hasham
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ddantes

ASKER

Thank you both for comments.  I had seen both of those articles, but don't know how to implement them.  

However, I did find code which accomplishes these tasks:

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "outlook"
WScript.Sleep 20000
WshShell.AppActivate "Outlook"
WScript.Sleep 1000
WshShell.SendKeys "{F9}"
WScript.Sleep 28000
Dim ObjOL 'As Outlook.Application
Set ObjOL = CreateObject("Outlook.Application")
If ObjOL Is Nothing Then
'no need to do anything, Outlook is not running
Else
'Outlook running
ObjOL.Session.Logoff
ObjOL.Quit
End If
Set ObjOL = Nothing