Platinum Partner

Automating Outlook With Ruby: Calendar Appointments

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
end

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

#   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
appointment.Save

Further details and discussion can be found here.
{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}