powerpoint - Opening a second presentation fails - Delphi XE2 + Windows 8 -
need open powerpoint presentation. using below statement.
var ppt: _application; pres: _presentation;
seek ppt := getactiveoleobject('powerpoint.application') _application; except ppt := createoleobject('powerpoint.application') _application ; end; ppt.visible := msotrue; seek pres := ppt.presentations.open(fpotx, msofalse, msotrue, msotrue); except on e:exception begin printtofile('error in phone call ppt.presentation.open' + e.message); end; end; it works fine whenever , createoleobject() in exception called. (i.e., no presentation open).
but above statement fails , if 1 presentation open. (i.e, ppt.presentations.open() called after getactiveoleobject() function).
using delphi xe2 , ms office 2013 , windows 8
this fails in windows 8 not in windows 7. in advance.
i don't know problem is, if delphi or office or windows version. code works no problem in windows 8.1 x64, delphi xe2 (32bit target), office 2007. unfortunately not have office 2013 test it.
i don't have type libs imported in delphi. tested using plain variant types.
if ppt isn't opened, code opens it. otherwise gets ole object. afterwards desired presentation opened. works tested it, no matter if ppt closed or opened.
... implementation uses comobj, activex; const msofalse = toleenum(false); msotrue = toleenum(true); {$r *.dfm} procedure tform1.button1click(sender: tobject); var ppt, pres: variant; begin ppt := unassigned; pres := unassigned; seek ppt := getactiveoleobject('powerpoint.application'); except ppt := createoleobject('powerpoint.application'); end; ppt.visible := msotrue; seek pres := ppt.presentations.open('c:\temp\test.pptx', msofalse, msotrue, msotrue); except on e:exception showmessage('oops'); end; end; edit
i tested imported powerpoint type lib. , code works 1:1 here:
... implementation uses comobj, activex, powerpoint_tlb; const msofalse = toleenum(false); msotrue = toleenum(true); {$r *.dfm} procedure tform1.button1click(sender: tobject); var ppt: _application; pres: _presentation; begin ppt := nil; pres := nil; seek ppt := getactiveoleobject('powerpoint.application') _application; except ppt := createoleobject('powerpoint.application') _application; end; ppt.visible := msotrue; seek pres := ppt.presentations.open('c:\temp\test.pptx', msofalse, msotrue, msotrue); except on e:exception showmessage('oops'); end; end; solution office 2013
as found out: seems work office 2013 when changing title parameter of ppt.presentations.open msofalse ==> ppt.presentations.open(fpotx, msofalse, msofalse, msotrue)
delphi powerpoint
No comments:
Post a Comment