Outlook Automation Part 2
Outlook Automation Part 2
Page 1 of 2
So how do we make Outlook Visible, like Word, Excel and the rest?
Outlook is the only one not to have a visible property. So the way we make Outlook visible is with the following code:
LOCAL loOutlook
AS Outlook.Application
LOCAL loNameSpace AS Outlook.NameSpace
LOCAL loExplorer AS Outlook.Explorer
#DEFINE olFolderDisplayNormal
loOutlook
= CREATEOBJECT('Outlook.Application')
loNameSpace = loOutlook.GetNamespace("MAPI")
loExplorer = loOutlook.Explorers.Add(loNameSpace.Folders[1],olFolderDisplayNormal)
loExplorer.Activate
The above code should open Outlook with the Outlook Today page.
Also to let you know at this point, you can make the individual folder pages visible, so for example if I wanted the Contacts Page to be visible, I can do this with the following code:
LOCAL loOutlook
AS Outlook.Application
LOCAL loNameSpace AS Outlook.NameSpace
LOCAL loContacts AS Object
#DEFINE olFolderContacts 10
loOutlook
= CREATEOBJECT('Outlook.Application')
loNameSpace = loOutlook.GetNamespace("MAPI")
loContacts = loNameSpace.GetDefaultFolder(olFolderContacts)
loContacts.Display
One thing to take note of is, that if Outlook is already running you will get a new window with just the contacts page, yet if Outlook is not running you will get the main Outlook window with the
contacts page open, so lets move on.
How do we get object references to the folders?
You can do this in a couple of ways.
1. You can go via the NameSpace.Folders collection like so:
loCalendar = loNameSpace.Folders[1].Folders["Calendar"]
2. The best way is to use the NameSpace.GetDefaultFolder Method like so:
#DEFINE olFolderCalendar
9
loCalendar = loNameSpace.GetDefaultFolder( olFolderCalendar )
At this point I will give you the list of Folders and there appropriate value:
ConstantValueConstantValueolFolderDeleted3olFolderContacts10olFolderOutbox4olFolderJournal11olFolderSent5olFolderNotes12olFolderInBox6olFolderTasks13olFolderCalendar9olFolderDrafts16
New to Outlook 2003 was the Junk folder this Constant is olFolderJunk Value = 23
So with these constants we can get the folders we need, so lets say I wanted to find out how many messages and folders the Inbox contained, so the way to do this is like so:
LOCAL loOutlook
AS Outlook.Application
LOCAL loNameSpace AS Outlook.NameSpace
LOCAL loInBox
AS Object
#DEFINE olFolderInBox
loOutlook
= CREATEOBJECT('Outlook.Application')
loNameSpace = loOutlook.GetNamespace("MAPI")
loInBox
= loNameSpace.GetDefaultFolder(olFolderInBox)
*-- At this point we have the InBox Object.
*-- Lets display how many messages we have in the Inbox.
? We have + TRANSFORM(loInBox.Items.Count) + Messages
*-- What about subfolders in the inbox.
? The inbox contains + TRANSFORM(loInBox.Folders.Count) + SubFolders
This next example obtains any Reminder Messages you have set using the Calendar.
LOCAL loOutlook
LOCAL loReminder
AS Outlook.Application
AS Object
loOutlook = CREATEOBJECT('Outlook.Application')
loReminder = loOutlook.Reminders
? We have + TRANSFORM(loReminder.Count) + Reminders setup
? These are:
FOR EACH loItem IN loReminder
? Caption: + loItem.Caption + ;
DateTime: + TRANSFORM(loItem.OriginalReminderDate)
ENDFOR
http://www.foxite.com/articles/print.aspx?id=72
18/09/2015
OUTLOOK AUTOMATION PART 2 - www.foxite.com - The Home Of The Visual Fox... Page 2 of 2
At this point you can see what the reminders are; you also have the following properties and methods available to you.
NextReminderDate (Property)
IsVisible (Property)
Snooze (Method)
Dismiss (Method)
Snooze takes a variant type parameter which is in minutes; the default is 5 minutes. Both Snooze and Dismiss will give you an OLE Error if the reminder is not visible, so you would have to check
with code like this:
LOCAL
LOCAL
LOCAL
LOCAL
LOCAL
loOutlook
loNameSpace
loInBox
loMess
lnUnRead
AS
AS
AS
AS
AS
Outlook.Application
Outlook.NameSpace
Object
Outlook.MailItem
Integer
#DEFINE olFolderInBox
loOutlook
loNameSpace
loInBox
lnUnRead
=
=
=
=
CREATEOBJECT('Outlook.Application')
loOutlook.GetNamespace("MAPI")
loNameSpace.GetDefaultFolder(olFolderInBox)
0
http://www.foxite.com/articles/print.aspx?id=72
18/09/2015