Microsoft Office Automation with Visual FoxPro
Getting a handle on Outlook
Although we use the same commands to start Outlook as the other Office applications, this is yet another area where things are different as much as they re the same. Again, VFP s CreateObject() function is the key to starting the Outlook Automation server. However, unlike the others, if Outlook is already open, this command:
oOutlook = CreateObject("Outlook.Application")
attaches to the running Outlook instance rather than starting a new one. It s as if you used GetObject(), not CreateObject(). In fact, you get the same result by issuing:
oOutlook = GetObject(,"Outlook.Application")
If Outlook isn t already running, then calling CreateObject() creates an instance, as you d expect. When you open Outlook this way, you run into yet another difference. As noted previously, Outlook s Application object doesn t have a Visible property. In order to make Outlook visible, so you can see what you re doing, you have to create and display an Explorer object, Outlook s face to the world. Here s the code:
#DEFINE olFolderDisplayNormal 0
oNameSpace = oOutlook.GetNameSpace("MAPI")
oExplorer = oOutlook.Explorers.Add(oNameSpace.Folders[1],olFolderDisplayNormal)
oExplorer.Activate()
The first line (after the #DEFINE) is likely to be the first line you issue anytime you start up a new instance of Outlook. It creates a NameSpace object within Outlook. NameSpace is at the top of the object hierarchy and is needed to climb down to other objects. (Actually, you can climb down by way of an Explorer, but for Automation work, you ll typically be working behind the scenes and won t need an Explorer.)
The next line creates an Explorer, telling it to display the first folder in the NameSpace created by the previous line. Then, the last line tells Outlook to show the newly created Explorer object. That s the line that s really equivalent to a Visible = .T. line. However, there s no corresponding Deactivate method. Once you activate the Explorer, the only way to make it go away is to call its Close method, which not only hides it, but destroys it, as well.
Once you have Outlook up and running, what can you do with it? That s what we re about to find out.
Copyright 2000 by Tamar E. Granor and Della Martin All Rights Reserved