2006-09Sep-29
Dealing with Outlook references
When you automate Outlook, you typically create a reference to Outlook.Application and then get the namespace using the GetNamespace() method. Everything you want to do is possible through the Namespace object. loNamespace.Application provides a nice reference back to Outlook. So why would one want to keep the additional reference around?
Local loOutlook, loNamespace, loInspector, loFolder
MessageBox("Please close Outlook now")
loOutlook = CreateObject("outlook.application")
loNamespace = loOutlook.GetNamespace("MAPI")
loOutlook = NULL
loFolder = loNamespace.GetDefaultFolder(6)
loFolder.Items(1).GetInspector.Activate()
MessageBox("Close Outlook window, please.")
loFolder.Items(1).GetInspector.Activate()
This code raises an error stating the GetInspector doesn't evaluate to an object. The first line worked fine, the exact same line after closing the outlook item doesn't work anymore. If you don't clear the reference in loOutlook, the code works just fine.