opening powerpoint presentations in ruby via win32ole

1

I've got this piece of code that works for Excel.

  require 'win32ole'
  excel = WIN32OLE.new('Excel.Application')
  excel.visible = true
  workbook = excel.Workbooks.Open('c:\file.xls');

But I have trouble getting the same thing done with for PowerPoint; This piece of code:

  require 'win32ole'
  ppt = WIN32OLE.new('Powerpoint.Application')
  ppt.visible = true
  presentation = ppt.Presentations.Open('c:\file.pptx');

Generates this error:

filename.rb in `method_missing': (in OLE method `Open': ) (WIN32OLERuntimeError)
OLE error code:80004005 in <Unknown>
<No Description>
HRESULT error code:0x80020009
Exception occurred.

Microsoft Support site says that the only required parameter is the filename.

ruby
powerpoint
win32ole
asked on Stack Overflow Feb 9, 2012 by 97-109-107

4 Answers

1

I've found an ugly workaround:

  require 'win32ole'
  require 'fileutils'

  ppt = WIN32OLE.new('PowerPoint.Application')
  ppt.visible = true
  system "start c:/presentation.ppt"
  puts ppt.ActivePresentation.Slides.Count()
  ppt.ActivePresentation.Slides(2).Export("filename.jpg", ".jpg", 1024,768)
  ppt.ActivePresentation.Close();
answered on Stack Overflow Feb 10, 2012 by 97-109-107
1

I put a 3 second wait and it fixes the problem

answered on Stack Overflow Feb 19, 2013 by user2087327
0

I got same error and adding ppt.visible = true was good enough for me.

answered on Stack Overflow Mar 24, 2015 by masaya
-1

Try using Add instead of Open or Connect

for example:

presentation = ppt.Presentations.Add('c:\file.pptx');

answered on Stack Overflow Jun 9, 2012 by David

User contributions licensed under CC BY-SA 3.0