我刚刚从办公室升级到了办公室2013.我的一个应用程序使用MSWord自动化将word转换为pdf。MS Word 2013变体不引用自动化对象
以下代码适用于Word 2007和2010,但不会在调用MSApp.Documents.open时收到上述OLEError。代码如下。有谁知道发生了什么问题?我也曾尝试剥离出所有PARAMS号召,打开其他不是文件名,但仍下落上述例外
Function convertToPDF(filename:string);
var MSApp, doc:variant;
begin
MSApp := CreateOLEObject('Word.Application');
try
MSApp.visible:=false;
MSApp:=MSApp.version;
version:=trunc(strToFloat(MSApp));
if version>11
then begin //should be greater than word 2003 so should have capability of printing to pdf
Doc:=MSApp.Documents.Open(fileName, false, true, false);
MSApp.ActiveDocument.SaveAs(outputfile, wdFormatPDF, emptyParam, emptyparam, false);
end;
finally
varclar(doc);
msApp.quit;
end;
end;
你确定这有效吗?我很确定它没有。无论是你的真实代码都不是你上面显示的代码。这似乎是高度可疑的:'MSApp:= MSApp.version;'你用你的版本号覆盖你的Word对象... –
你发布的代码从来没有在任何Delphi版本中工作过,因为它完全不正确。 –
谢谢Ken,但请准备好我的评论。我解释了这一点。 –