Over a million developers have joined DZone.

Automating Outlook With Ruby: Calendar Appointments

DZone's Guide to

Automating Outlook With Ruby: Calendar Appointments

Free Resource
From the Ruby on Windows blog.

Use Ruby to extract appointments data from the Microsoft Outlook Calendar, delete an appointment, and create a new appointment.

require 'win32ole'

outlook = WIN32OLE.new('Outlook.Application')
mapi = outlook.GetNameSpace('MAPI')
calendar = mapi.GetDefaultFolder(9)

#   reading calendar data
data = []
calendar.Items.each do |appointment|
    rec = []
    rec << appointment.Subject
    rec << appointment.Location
    rec << appointment.Start
    rec << appointment.Duration
    rec << appointment.End
    rec << appointment.Body
    data << rec

#   deleting an appointment
calendar.Items.each do |appointment|
    if appointment.Subject == 'Punch Bud Selig in the Nose'

#   creating a new appointment
appointment = outlook.CreateItem(1)
appointment.Start = '7/29/2007 11:00 AM'
appointment.Duration = 300
appointment.Subject = 'Baseball Hall of Fame Induction'
appointment.Body = 'Tony Gwynn and Cal Ripken Jr.'
appointment.Location = 'Cooperstown, NY'
appointment.ReminderMinutesBeforeStart = 15
appointment.ReminderSet = true

Further details and discussion can be found here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}