Sunday, 23 January 2011


Part 1: Introduction
What is MS Outlook?
We have to know the MS Outlook.  It is an application/software that provides much functionality such as sending & receiving emails, managing your tasks, calendar, contacts and many other things.
How do you actually start with the automation of MS Outlook? 
Here we introduce first basics of Outlook automation and later move on to the advanced topics.
MS Outlook also provides a set of classes and interfaces using which you can perform the above mentioned Outlook tasks through code without directly doing it manually in Outlook. So all you have to do is write some code that will first access the classes and interfaces exposed by MS Outlook. Once this is done, you would have access to all the methods and properties using which you can perform various Outlook tasks such as sending mails, creating new folders, distribution lists etc. This set of classes & interfaces is collectively called the Outlook Object Model.
How to create a sample script in QTP that would access the Outlook Object Model and use it to open Outlook and display the Inbox folder. 
In the Outlook Object Model, ‘Application’ Object is the topmost or parent Object that represents the entire Outlook Application. So we’ll first create an instance of Outlook.Application object.
Set objOutlook = CreateObject("Outlook.Application")



Once this is done, we’ll then use GetNamespace method to bind to the MAPI namespace.
Set objNameSpace = objOutlook.GetNamespace("MAPI")


Next, we have to create a reference to the inbox folder and then display it. This can be done using the below lines of code –
Const olFolderInbox = 6  'Inbox folder in Outlook is referenced through value 6
Set objFolder = objNameSpace.GetDefaultFolder(olFolderInbox)
objFolder.Display



You can also play around with other properties and methods of the Application object. [To view the entire list of properties and methods available with the application object, you can refer the Outlook Object Model Documentation from MSDN Library.]
Set objAllReminders = objOutlook.Reminders
msgbox objAllReminders.Count
'Check the version of the Outlook installed
msgbox  objOutlook.Version
'Check the Product Code - Microsoft Outlook globally unique identifier (GUID).
msgbox  objOutlook.ProductCode
'Close MS Outlook
objOutlook.Quit()

First to check if outlook is already open or not, and open Outlook only if it is not already open. Let’s see the full code for the same.
Sample Code 1: How to Open & Close Outlook using QTP
'Check if outlook is already open
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objTaskMgrProc = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'outlook.exe'")

'If outlook is not open, then open it
If objTaskMgrProc.Count = 0 Then
Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(6)
objFolder.Display
'Check the total number of reminders available
Set objAllReminders = objOutlook.Reminders
msgbox objAllReminders.Count
'Close Outlook
objOutlook.Quit()
Else
msgbox "Outlook already open"
End If
















0 comments:

Post a Comment

TrainingHUB. Powered by Blogger.

Total Pageviews

THE BEST QTP TRAINING INSTITUTE IN HYDERABAD

QTP Training in hyderabad

Sql Tutorial

Popular Posts

Our Facebook Page

TrainingHUB

Followers