Friday, August 21, 2009
QTP Script to show the name of the Inbox folder in the message box.
A very simple four line example to show the name of the Inbox folder in the message box. For this example make sure that Microsoft Outlook is open (I have used Outlook 2007). Write the below code in a new test in QTP and run it. It will show a message box with “Inbox” written in it.
'using the CreateObject method to create an Outlook Application object.
Set olApp = CreateObject("Outlook.Application")
'GetNameSpace - Returns a NameSpace object of the specified type. It exists because outlook was designed to be usable with different kinds of data, each of which would be identified by its own namespace. So far, only one kind of data is supported in Outlook, MAPI data (Messaging Applicaiton Programming Interface).
Set olns = olApp.GetNameSpace("MAPI")
'GetDefaultFolder - Returns a MAPIFolder object that represents the default
'folder of the requested type for the current profile
Set MyFolder = olns.GetDefaultFolder(6)
See most commonly used folder types:
olFolderDeletedItems = 3
olFolderOutbox = 4
olFolderSentMail = 5
olFolderInbox = 6
olFolderCalendar = 9
olFolderJournal = 11
olFolderNotes = 12
olFolderTasks = 13
olFolderDrafts = 16
More on these OlDefaultFolders Enumeration here.
QTP & Microsoft Outlook Object Model
QTP Script to count emails in any Outlook folder
QTP Script to enumerate all folders in Outlook
QTP Script to send an email from Outlook
QTP Script to send an email with attachment from Outlook
QTP Script to read an email from Outlook
QTP Script to download an email attachment from Outlook
Posted by Sachin Dhall at 10:12:00 AM