Encrypt a Word document in VBA

I want to create a macro that in certain situations will encrypt the current 
document such that when the document is saved and opened again, Word will ask 
for the password (similarly to the user selecting the Office Button -> 
Prepare -> Encrypt Document). 

Would someone tell me how this can be done?  Thanks for any help.

0
Utf
6/1/2010 2:19:01 PM
word.vba.general 1023 articles. 1 followers. Follow

3 Replies
3590 Views

Similar Articles

[PageSpeed] 42

To set a password ...

    ActiveDocument.Password = "whatever"

To save with a password ...

    ActiveDocument.SaveAs name_etc., Password:="whatever"

-- 
Enjoy,
Tony

 www.WordArticles.com

"JeffG" <JeffG@discussions.microsoft.com> wrote in message 
news:00FD01C1-E5E9-4D8B-98C2-28E616BDFFED@microsoft.com...
>I want to create a macro that in certain situations will encrypt the 
>current
> document such that when the document is saved and opened again, Word will 
> ask
> for the password (similarly to the user selecting the Office Button ->
> Prepare -> Encrypt Document).
>
> Would someone tell me how this can be done?  Thanks for any help.
> 

0
Tony
6/1/2010 3:43:21 PM
Thanks for the response.  That worked beautifully, but raises another 
question.  how good is the encryption and how easily can it be broken?

"Tony Jollans" wrote:

> To set a password ...
> 
>     ActiveDocument.Password = "whatever"
> 
> To save with a password ...
> 
>     ActiveDocument.SaveAs name_etc., Password:="whatever"
> 
> -- 
> Enjoy,
> Tony
> 
>  www.WordArticles.com
> 
> "JeffG" <JeffG@discussions.microsoft.com> wrote in message 
> news:00FD01C1-E5E9-4D8B-98C2-28E616BDFFED@microsoft.com...
> >I want to create a macro that in certain situations will encrypt the 
> >current
> > document such that when the document is saved and opened again, Word will 
> > ask
> > for the password (similarly to the user selecting the Office Button ->
> > Prepare -> Encrypt Document).
> >
> > Would someone tell me how this can be done?  Thanks for any help.
> > 
> 
> .
> 
0
Utf
6/2/2010 12:40:01 PM
If you use a strong password, it will be strong.  If you use a weak one, it 
will be weak.

The stronger the password, the stronger the protection.

-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"JeffG" <JeffG@discussions.microsoft.com> wrote in message 
news:EC7C5616-1AAE-4AE4-A00B-74F099A15BC1@microsoft.com...
> Thanks for the response.  That worked beautifully, but raises another
> question.  how good is the encryption and how easily can it be broken?
>
> "Tony Jollans" wrote:
>
>> To set a password ...
>>
>>     ActiveDocument.Password = "whatever"
>>
>> To save with a password ...
>>
>>     ActiveDocument.SaveAs name_etc., Password:="whatever"
>>
>> -- 
>> Enjoy,
>> Tony
>>
>>  www.WordArticles.com
>>
>> "JeffG" <JeffG@discussions.microsoft.com> wrote in message
>> news:00FD01C1-E5E9-4D8B-98C2-28E616BDFFED@microsoft.com...
>> >I want to create a macro that in certain situations will encrypt the
>> >current
>> > document such that when the document is saved and opened again, Word 
>> > will
>> > ask
>> > for the password (similarly to the user selecting the Office Button ->
>> > Prepare -> Encrypt Document).
>> >
>> > Would someone tell me how this can be done?  Thanks for any help.
>> >
>>
>> .
>> 
0
Doug
6/2/2010 10:59:30 PM
Reply:

Similar Artilces: