 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Herbert dela Cruz Guest
|
Posted: Thu Sep 07, 2006 2:14 am Post subject: Opening Password Protected Word Docs |
|
|
Hello!
I'm a newbie with automation using Delphi, and thanks to the internet
and newsgroups such as this, I was able to create a basic app which is
basically a form with an OleContainer containing a Word object.
My question is: Is there a way to automate the opening of password
protected files? When I tried to open a password protected file, the
Word server (I'm not sure if this is the correct term) opens up to
display the dialog asking for the file password. I would want this
"automated" so that the user: 1) doesn't see the Word server opening,
and more specially, 2) the user doesn't need to type in the password.
Thanks for your help.
- Herbert = |
|
| Back to top |
|
 |
Oliver Townshend Guest
|
Posted: Thu Sep 07, 2006 6:20 am Post subject: Re: Opening Password Protected Word Docs |
|
|
| Quote: | My question is: Is there a way to automate the opening of password
protected files? When I tried to open a password protected file, the
Word server (I'm not sure if this is the correct term) opens up to
display the dialog asking for the file password. I would want this
"automated" so that the user: 1) doesn't see the Word server opening,
and more specially, 2) the user doesn't need to type in the password.
|
It's an argument of the open function. The word VBA help says:
expression.Open(FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument,
WritePasswordTemplate, Format, Encoding, Visible, OpenConflictDocument,
OpenAndRepair , DocumentDirection, NoEncodingDialog)
PasswordDocument Optional Variant. The password for opening the document.
so you should be fine if you use that.
You can work out how most things work in Word if you record a macro of that
action, and then translate the VBA code into Delphi.
The VBA Help files are vital as well. On my PC they are in "C:\Program
Files\Microsoft Office\OFFICE11\1033\VBAWD10.CHM".
Oliver Townshend |
|
| Back to top |
|
 |
Herbert dela Cruz Guest
|
Posted: Thu Sep 07, 2006 8:12 am Post subject: Re: Opening Password Protected Word Docs |
|
|
Hello again!
I've managed to do what I wanted. Thanks for the pointers and thanks
to all who have gone before me and paved the way for me to be able to
experiment.
Although my code isn't elegant, hopefully someone else might find it
useful.
-- begin code
procedure TForm1.Button1Click(Sender: TObject);
var
range: Variant;
FileName, Password: OLEVariant;
begin
try
Word := GetActiveOleObject('Word.Application');
except
Word := CreateOleObject('Word.Application');
end;
FileName := 'C:\temp\t2.doc';
Password := 'thepass';
//open the doc
Word.Documents.Open (FileName, EmptyParam, EmptyParam, EmptyParam,
Password, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
//copy the contents
range := Word.ActiveDocument.Content;
range.Select;
range.Copy;
//paste it into the OleContainer
OleContainer1.CreateObject('Word.Document.8',False);
OleContainer1.Paste;
OleContainer1.DoVerb (ovPrimary);
end;
-- end code |
|
| Back to top |
|
 |
Herbert dela Cruz Guest
|
Posted: Thu Sep 07, 2006 8:12 am Post subject: Re: Opening Password Protected Word Docs |
|
|
Hello!
First off, sorry for that double post. I'm using a new newsreader
program and I didn't know that it could actually resend something that
was already sent.
Secondly, thanks Oliver, for your response.
| Quote: | You can work out how most things work in Word if you record a macro of that
action, and then translate the VBA code into Delphi.
|
Just tried it, and I now have the VBA code. I guess my next problem is
where do I use it? I can't see any Open function/procedure in
TWordApplication, TWordDocument, or TOleContainer.
Once again, many many thanks! |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|