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.

97-109-107
  • 95
  • 1
  • 10

4 Answers4

1

I put a 3 second wait and it fixes the problem

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();
97-109-107
  • 95
  • 1
  • 10
0

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

masaya
  • 410
  • 2
  • 9
  • 15
-1

Try using Add instead of Open or Connect

for example:

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

David
  • 1