# Protect and Upprotect - Word 2007 Doc



## Toast83 (Mar 28, 2013)

Mornin',


I've got a template in Word 2007 that I'm creating that several people will be using and, to avoid issues from people accidentally changing or deleting stuff in the document, I'm restricting editting to form fields only and password protecting it. What I want to happen is for the macro to run, unprotect the document, save it as a separate, macro-free file and then protect the document WITHOUT the password in order to prevent people from accidentally making changes, but allowing them to make intentional edits in case they need to reformat, clean up data, etc.

So my template starts out as protected and here's the code that I'm using:


```
Pwd="Password"
ActiveDocument.Unprotect Password:=Pwd
'...
'rest of code here
'...
Pwd = ""
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=Pwd
ActiveDocument.SaveAs "OtherFile.doc"
```

The problem I'm running into is that, when I close the document and open the "OtherFile.doc" that was saved, it still has "Password" as the password. I've tried it without defining a password before it's saved at all as well as not using a variable and just an emplty string, so 
	
	
	
	
	
	



```
Password:=""
```
 at the end, but it all results in the same - which I expected but thought it worth a shot.

Any suggestions on how to remedy this?


Best Regards,

RCT


----------



## Macropod (Mar 28, 2013)

Since you're using Word 2007, why not take advantage of its editing restrictions. They're far more flexible than what formfields provide and don't require macros or passwords.


----------



## Toast83 (Mar 29, 2013)

Paul,


Thanks for the input, but the template is a little more complex in that it's designed to make a certain process we have much more automated. Our current process requires our employees to cut and paste certain cells from an Excel file into the document which is then provided to our clients to provide to their employees as a notice of changes in the services available to them. This process was causing some of the less technologically inclined some issues, so I designed the template to automatically pull from the Excel file and populate the tables and form fields in the docuemnt. Some of the information from the Excel file may need tweaking, so I plan on leaving the form fields so that the information can be changed without changing the whole document. If the user wants to edit the document, they have that option, but I want to make it a little more difficult so that the changes are more deliberate.

I'm not in a very tech savvy industry - I'm actually still in the early stages of learning myself - so I'm trying to make this as idiot proof as I can


----------



## Macropod (Mar 29, 2013)

OK, If your macro is in the form's template (ie a .dot file), it will be available to all files based on that template - while they're on your system - but not available elsewhere. Accordingly, the clients would never see the code or the password. Conversely, if you do include the code in the documents, you can password-protect the vba module it's in, so that no-one who doesn't know the module's password can see the code in it.


----------



## Toast83 (Apr 2, 2013)

I hadn't thought about password protecting the macro, so thanks for that. What I'm concerned about more here is the document itself, though. I have bookmarks in the document that I call on in the macro to skip around and add/remove sections as needed. What I don't want to happen is for someone to accidentally delete a bookmark and then the macro not work properly, for one, and make it so they can only make deliberate changes in the new document that is created. It's not for any true security, simply to dummy proof it, but I can't seem to find any reason why the password reverts to the original password instead of it not having one... Is that something that Word does often?

Thanks, again, for your help.

Also, not a true template and the macro is going to follow the document until the new one is populated and saved. Sorry for the confusion on that.


----------



## Macropod (Apr 2, 2013)

Relying on bookmarks in editable portions of a document is fraught with danger. As you've observed, they might get deleted. They might even get cut & pasted to an entirely different location. Since you're using Word 2007, you might do better to use the 'read-only' restrictions and mark out the exception areas that people are allowed to edit. If you then keep the bookmarks in the restricted portions, they'll not be in danger of deletion/moving.

It tested your code and cannot replicate your experience - the original password gets deleted as the code implies it should.


----------

