Encrypt a Word document in VBA

J

JeffG

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.
 
T

Tony Jollans

To set a password ...

ActiveDocument.Password = "whatever"

To save with a password ...

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

JeffG

Thanks for the response. That worked beautifully, but raises another
question. how good is the encryption and how easily can it be broken?
 
D

Doug Robbins - Word MVP

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top