I’m trying to make a Ruby Script that adds contacts to Microsoft
outlook via Ruby’s Win32OLE and MAPI. So it works for the most part, but
I’m having trouble trying to handle exceptions… The big problem right
now is that the contacts need to go into a subfolder. However, if the
current mailbox doesn’t have the specified subfolder, it kicks an
exception. Thus, I added a line of code to add that folder. However, if
the folder doesn’t exist, it kicks an error, and if it tries to create
it when it does exist, it kicks an error. I’ve tried IF statements and
UNLESS statements, but I’m not getting anywhere… My code is as
outlook = WIN32OLE.new(‘Outlook.Application’)
mapi = outlook.GetNameSpace(‘MAPI’)
contacts_folder = mapi.GetDefaultFolder(10)
if contacts_folder.Folders(“Company Contacts”)
co_contacts = mapi.GetDefaultFolder(10).Folders(“Company Contacts”)
co_contacts = mapi.GetDefaultFolder(10).Folders.Add(“Company
when contacts_folder.Folder(“Company Contacts”) does not exist, it
doesn’t do the ELSE portion of the IF statement. It kicks me the error
“The operation failed. An object could not be found”. Does anyone know
how to handle this?
Any help is appreciated!!
- Jeff M.