BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Saving Password Protected Word Files

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Herbert dela Cruz
Guest





PostPosted: Mon Sep 11, 2006 4:51 pm    Post subject: Saving Password Protected Word Files Reply with quote



Hi everyone!

This is somewhat related to my earlier posts, but this time, instead of
opening password protected docs, my problem is with saving them. My code
is below:

=== begin code ===

ShowMessage (PassedWord);
if docSaved Then Exit;
OleContainer.SaveAsDocument(FileName);
OleContainer.Close;
WordApp.Documents.Open (FileName, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam);
WordApp.ActiveDocument.Password := Passedword;
WordApp.ActiveDocument.Save;
WordApp.ActiveDocument.Close(EmptyParam, EmptyParam, EmptyParam);
If Not (isQuitting) Then OleContainer.DoVerb(ovPrimary);
docSaved := True;

=== end code ===

The PassedWord variable is the password to be used to protect the
document. And I derived the code from this VBA:

== begin VBA code ===

With ActiveDocument
.ReadOnlyRecommended = False
.EmbedTrueTypeFonts = False
.SaveFormsData = False
.SaveSubsetFonts = False
.Password = "test"
.WritePassword = ""
.OptimizeForWord97 = False
End With
Application.DefaultSaveFormat = ""
ActiveDocument.Save

=== end VBA code ===

Thanks for the help. :D

Cheers!
Back to top
Mike Shkolnik
Guest





PostPosted: Tue Sep 12, 2006 1:06 am    Post subject: Re: Saving Password Protected Word Files Reply with quote



Hi,

you need call the Protect method before Save instead change the Password
property:

document.Protect(Password := yourPassword);
document.SaveAs(yourFileName);
document.Close;

--
With best regards, Mike Shkolnik
E-mail: mshkolnik (AT) scalabium (DOT) com
WEB: http://www.scalabium.com

"Herbert dela Cruz" <renegade_havoc (AT) yahoo (DOT) com> wrote in message
news:MPG.1f6fce8142f60038989684 (AT) newsgroups (DOT) borland.com...
Quote:
Hi everyone!

This is somewhat related to my earlier posts, but this time, instead of
opening password protected docs, my problem is with saving them. My code
is below:

=== begin code ===

ShowMessage (PassedWord);
if docSaved Then Exit;
OleContainer.SaveAsDocument(FileName);
OleContainer.Close;
WordApp.Documents.Open (FileName, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam, EmptyParam);
WordApp.ActiveDocument.Password := Passedword;
WordApp.ActiveDocument.Save;
WordApp.ActiveDocument.Close(EmptyParam, EmptyParam, EmptyParam);
If Not (isQuitting) Then OleContainer.DoVerb(ovPrimary);
docSaved := True;

=== end code ===

The PassedWord variable is the password to be used to protect the
document. And I derived the code from this VBA:

== begin VBA code ===

With ActiveDocument
.ReadOnlyRecommended = False
.EmbedTrueTypeFonts = False
.SaveFormsData = False
.SaveSubsetFonts = False
.Password = "test"
.WritePassword = ""
.OptimizeForWord97 = False
End With
Application.DefaultSaveFormat = ""
ActiveDocument.Save

=== end VBA code ===

Thanks for the help. :D

Cheers!
Back to top
Oliver Townshend
Guest





PostPosted: Tue Sep 12, 2006 2:17 am    Post subject: Re: Saving Password Protected Word Files Reply with quote



Quote:
you need call the Protect method before Save instead change the Password
property:

document.Protect(Password := yourPassword);
document.SaveAs(yourFileName);
document.Close;

Protecting a document with a password isn't the same as saving it with a
password. Protect allows you to open the document but not alter it, whereas
password protection at open/save stops you opening it altogether.

Oliver Townshend
Back to top
Herbert dela Cruz
Guest





PostPosted: Tue Sep 12, 2006 7:10 pm    Post subject: Re: Saving Password Protected Word Files Reply with quote

Hi!

Quote:
Protecting a document with a password isn't the same as saving it with a
password. Protect allows you to open the document but not alter it, whereas
password protection at open/save stops you opening it altogether.


Which was what I thought I was doing with the
WordApp.ActiveDocument.Password line. However, the document doesn't save
the password. Is there something else missing, perhaps?

Thanks for the help. :D

Cheers!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.