Jan 24
Over at the Ruby on Windows blog, David posted an article about how the latest versions of Office allow for saving files as PDF. Which prompted me to ask how you can find out what the versions are, since Office 2003 apps don’t have this option. So in between watching the AFC Championship game, I figured it out and came up with the following program:
require 'win32ole'
xl = WIN32OLE.new('Excel.Application')
xl.visible = false
ver = nil
case xl.Version
when "12.0"
ver = "Excel 2007"
when "11.0"
ver = "Excel 2003"
else
ver = "{Unknown Version => #{xl.Version}}"
end
puts " Excel Version: #{ver}"
xl.Quit
word = WIN32OLE.new('Word.Application')
word.visible = false
ver = nil
case word.Version
when "12.0"
ver = "Word 2007"
when "11.0"
ver = "Word 2003"
else
ver = "{Unknown Version => #{word.Version}}"
end
puts " Word Version: #{ver}"
word.Quit
ppt = WIN32OLE.new('Powerpoint.Application')
#ppt.visible = false ## Powerpoint 2007 does not allow itself to be hidden?!?
ver = nil
case ppt.Version
when "12.0"
ver = "Powerpoint 2007"
when "11.0"
ver = "Powerpoint 2003"
else
ver = "{Unknown Version => #{ppt.Version}}"
end
puts "Powerpoint Version: #{ver}"
ppt.Quit
ol = WIN32OLE.new('Outlook.Application')
#ol.visible = false
ver = nil
## Outlook seems to tack on a build number
tt = ol.Version.slice(0,4)
case tt
when "12.0"
ver = "Outlook 2007"
when "11.0"
ver = "Outlook 2003"
else
ver = "{Unknown Version => #{ol.Version}}"
end
puts " Outlook Version: #{ver}"
ol.Quit
Tagged with: Excel • Office • outlook • Powerpoint • Ruby • WIN32OLE • Word
Dec 06
While running a simple enum of my Outlook inbox, I came across an error:
irb(main):005:0>require 'win32ole'
irb(main):006:0>ol = WIN32OLE.new('Outlook.Application')
irb(main):023:0>mapi = ol.GetNameSpace('MAPI')
irb(main):024:0>inbox = mapi.GetDefaultFolder(OutlookConst::OlFolderInbox)
irb(main):031:0>inbox.Items.each { |m| p.To }
ALLEN, JOHN
ALLEN, JOHN; xxxx
...
WIN32OLERuntimeError: unknown property or method `To'
HRESULT error code:0x80020006
Unknown name.
from (irb):83:in `method_missing'
from (irb):83
from (irb):83:in `each'
from (irb):83
Huh?? A message without a ‘To’ line? What gives? Poking around a bit more I get the item into an object to look at, and find out its an AppointmentItem, and not a normal email message. I’m thinking there is some property of the Item object that will tell me what kind of message it is. After some more digging around on the Internet, I find a reference to a MessageClass property. So if I modify my code a bit, I can list all the ‘To’ lines from all the messages I’m interested in looking at:
inbox.Items.each do |msg|
puts "Unread:#{msg.To}" if msg.Unread && !msg.MessageClass[/Meeting/]
puts "Meeting:#{msg.Subject}" if msg.MessageClass[/Meeting/]
end
The MessageClass properties of all the emails in my inbox are:
“IPM.Note” => Regular EMail
“IPM.Schedule.Meeting.Request” => Meeting Request
“IPM.Schedule.Meeting.Resp.Pos” => Meeting Accept
“IPM.Schedule.Meeting.Canceled” => Meeting Canceled
I’m sure there’s a Meeting Decline message class….I just don’t happen to have it right now.
“IPM.Note.Rules.OofTemplate.Microsoft” => Out of Office message.
I’m sure there are more types…I’ll add to this post as I find more.
Tagged with: inbox • outlook • Ruby • WIN32OLE