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.
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();
I put a 3 second wait and it fixes the problem
I got same error and adding ppt.visible = true
was good enough for me.
Try using Add instead of Open or Connect
for example:
presentation = ppt.Presentations.Add('c:\file.pptx');
User contributions licensed under CC BY-SA 3.0