需要打开一个PowerPoint演示文稿。我正在使用以下声明。
Var ppt:_Application,pres:_Presentation;
try
ppt := GetActiveOleObject('PowerPoint.Application') as _Application;
except
ppt := CreateOleObject('PowerPoint.Application') as _Application ;
end;
ppt.Visible := msoTrue;
try
pres := ppt.Presentations.Open(FPOTX, msoFalse, msoTrue, msoTrue);
except
on e:exception do begin
printtofile('Error in call to ppt.Presentation.Open' + e.message);
end;
end;每当异常调用CreateOleObject()时,它都能正常工作。(即尚未开始发言)。
但是,如果一个演示文稿已经打开,上述语句将失败。(即,ppt.Presentations.Open()在GetActiveOleObject()函数之后调用)。
使用Delphi XE2,MS Office 2013,Windows 8
这只在Windows 8中失败,而在Windows 7中失败。谢谢。
发布于 2014-06-23 09:56:51
我不知道问题出在哪里,是你的Delphi、Office还是Windows版本。但是这段代码在Windows8.1 x64,Delphi XE2 (32位目标),Office 2007中没有问题。不幸的是,我没有Office 2013来测试它。
我没有进口任何类型的LIBs在我的德尔菲。所以我只使用普通的Variant类型来测试它。
如果没有打开PPT,代码就会打开它。否则,它将获得OLE对象。然后,打开所需的演示文稿。无论PPT是关闭还是打开,我测试它的频率都是一样的。
...
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;
try
ppt := GetActiveOleObject('PowerPoint.Application');
except
ppt := CreateOleObject('PowerPoint.Application');
end;
ppt.Visible := msoTrue;
try
pres := ppt.Presentations.Open('C:\Temp\Test.pptx', msoFalse, msoTrue, msoTrue);
except
on E:Exception do
ShowMessage('OOPS');
end;
end;编辑
我还用导入的PowerPoint类型Lib对其进行了测试。您的代码在这里工作1:1:
...
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;
try
ppt := GetActiveOleObject('PowerPoint.Application') as _Application;
except
ppt := CreateOleObject('PowerPoint.Application') as _Application;
end;
ppt.Visible := msoTrue;
try
pres := ppt.Presentations.Open('C:\Temp\Test.pptx', msoFalse, msoTrue, msoTrue);
except
on E:Exception do
ShowMessage('OOPS');
end;
end;2013年办公室的解决方案
正如您已经发现的:当将Office 2013的Title参数ppt.Presentations.Open更改为msoFalse ==> ppt.Presentations.Open(FPOTX, msoFalse, msoFalse, msoTrue)时,它似乎与msoFalse一起工作。
发布于 2014-06-26 07:51:43
这对我来说是完全没有问题的。面临的问题是XXX.pot(Office1997-2003)和XXX.potx (office2014)之间的兼容性问题。除此之外,一切都很好。
https://stackoverflow.com/questions/24360465
复制相似问题