PDA

View Full Version : Automate password protecting a document



Chris_cs
01-23-2008, 04:02 AM
Is it possible to have a button in word that will allow you to save the document with a password?

I only need some advice on the syntax for the password bit so any help would be appreciated.

Thanks in advance

fumei
01-23-2008, 04:13 AM
Why not just use the menu dialog?

However, is it possible? Yes. It is a simple one line.ActiveDocument.Password = "blah"

Once saved, the password to open it is "blah".

Did you look up anything in Help? It is very simple and clear, there, in Help.

You do not state if this is a new document, and should use a SaveAs, or an existing document, and should use Save.

Whatever one it is, just put the saving instruction after the Password instruction.

Chris_cs
01-23-2008, 04:31 AM
Thanks fumei. I didn't realise it was as simple as that because I also found some info of the web. It will be when saving a new document so I should be able to figure this out.

Thanks for your help.

fumei
01-23-2008, 11:21 AM
"because I also found some info of the web"

I strongly suggest, and recommend, that you actually use VBA Help. It is much much better than it used to be.

If you had simply typed (and nothing else) :

password

in any code module and pressed F1 (for Help) it would have displayed exactly the information you needed.

F1 is your friend.

Chris_cs
01-29-2008, 04:12 AM
Now I have the password thing sorted I'd also like to ask how to create a button that could turn something on or off. For example, I'm trying to give the user the option to protect the document by tracking changes. I'd like the user to be able to turn this on or off but I'm not quite sure how to do this.

Any ideas?

fumei
01-29-2008, 11:34 AM
I am failing to see the point to these. Perhaps you can explain what is the business case for this?

" I'm trying to give the user the option to protect the document by tracking changes. I'd like the user to be able to turn this on or off but I'm not quite sure how to do this."

The user already HAS the option to turn this off and on...it is called using the menus. You are not giving it to them, they already have it.

"How to create a button to turn something on or off."

What kind of a button?

WHY?

However, the answer is:

1. make a button
2. add the code to turn something on or off

If you can be more specific, then the answer may get more specific.