开发者

The requested object does not exist (0x80010114) when loading Word-document into OleContainer

开发者 https://www.devze.com 2023-02-21 17:31 出处:网络
I created a Word document through automation (Start Word, Open template, Saved it to .doc, Close document, Quit Word). After that I want to open this .doc-file in an TOleContainer: fOleContainer.Creat

I created a Word document through automation (Start Word, Open template, Saved it to .doc, Close document, Quit Word). After that I want to open this .doc-file in an TOleContainer: fOleContainer.CreateObjectFromFile(lTempFileName, False);.

But a client of ours who uses Word 2010 (several machines, Windows 7 / Windows XP) gets an error on that line: The requested object does not exist (0x80010114).

What is causing this error and how can I solve this?

Code:

procedure CreateNewWordDocument(const aFile, aTemplate: string);
var
  lApp: WordApplication;
  lDocuments: Documents;
  lDoc: WordDocument;
  lFileName: OleVariant;
  lTemplate: OleVariant;
begin
  lApp := CoWordApplication.Create;
  lDocuments := lApp.Documents;
  if aTemplate = '' then
    lDoc := lDocuments.AddOld(EmptyParam, olFalse)
  else
  begin
    lFileName := aTemplate;
    lDoc := lDocuments.AddOld(lFileName, olFalse);
  end;

  lDocuments := nil;
  lFileName := aFile;
  lTemplate := lDoc.Get_AttachedTemplate;
  lTemplate.Saved := True;
  lTemplate := lApp.NormalTemplate;
  lTemplate.Saved := True;
  lTemplate := Null;
  lDoc.SaveAs2000(lFileName, olwdFormatDocument, EmptyParam, EmptyParam, olFalse,
    EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
  lDoc.Close(olwdDoNotSaveChanges, EmptyParam, EmptyParam);
  lDoc := nil;
  lApp.Quit(olwdDoNotSaveChanges, EmptyParam, EmptyParam);
  lApp := nil;
开发者_高级运维end;

...
CreateNewWordDocument('c:\windows\temp\~tmp2343.tmp.doc', 'c:\mytemplate.dot');
fOleContainer.CreateObjectFromFile(lTempFileName);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号