Board index » delphi » Opening password-protected file with embedded OLE-Word

Opening password-protected file with embedded OLE-Word

Hello all,

I need to diplay Word as an embedded OLE application within a Delphi program and open a password protected Word file.

I used the TOleContainer component to embed Word. Everything works fine, only the OleContainer just offers the CreateObjectFromFile method that does not take any parameter to pass the password.
Opening the protected file with the CreateObjectFromFile method causes the Word instance to ask the user for the password. But that doesnt help me much because in my case the user doesnt know the password its only
known by the Delphi app. Therefore I am forced to pass it....

I would be thankfull for any kind of help!

kind regards, Thomas

 

Re:Opening password-protected file with embedded OLE-Word


<<Thomas Bohn:
I need to diplay Word as an embedded OLE application within
a Delphi program and open a password protected Word file.

Quote

Open the file using an invisible instance of Word, then
display it in the TOleContainer:

var
  DataObj: IDataObject;
  CrInfo: TCreateInfo;
  FileName, Password: OleVariant;
begin
  WordApp.Connect;
  FileName := 'D:\Docs\Quotations.doc';
  Password := 'Password';
  WordApp.Documents.Open(FileName, EmptyParam, EmptyParam,
              EmptyParam, Password, EmptyParam,
              EmptyParam, EmptyParam, EmptyParam,
              EmptyParam, EmptyParam, EmptyParam);
  WordDoc.ConnectTo(WordApp.ActiveDocument as _Document);
  DataObj := WordDoc.DefaultInterface as IDataObject;
  with CrInfo do
  begin
    CreateType := ctFromData;
    DataObject := DataObj;
    ShowAsIcon := False;
  end;
  OleContainer1.CreateObjectFromInfo(CrInfo);
  OleContainer1.DoVerb(ovShow);

Don't forget to close the invisible Word when you've
finished.

--
Deborah Pate (TeamB) http://delphi-jedi.org

  Use Borland servers; TeamB don't see posts via ISPs
  http://www.borland.com/newsgroups/genl_faqs.html

Other Threads