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

1

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);
delphi
com
ms-word
automation
ole
asked on Stack Overflow Mar 31, 2011 by The_Fox • edited Feb 25, 2015 by Deduplicator

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0