Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Automating Outlook with Ruby: Calendar Appointments (See related posts)

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.

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts