Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a macro to protect a document

Status
Not open for further replies.

prirod

Technical User
Oct 14, 2003
10
US
Can someone give me sample code on how to protect a document after it has been initialized by a macro? I can't protect the document to begin with because it is a template that has a couple of macros that insert text into specific fields. The template also has a form with checkboxes in it. If you protect the document, the checkboxes work, but the fields that the macro addresses cannot be edited, at least not to my knowledge anyway, so I want to create a macro that will automatically protect the document after the template has been opened and the macros have run. I appreciate any help offered. Thanks
 
First, a word about Excel 'security'. It is important for you to know that anyone who really wants to bypass the protection of a locked workbook or worksheet can do so, and they needn't be a 'hacker' to do it. Less than 10 minutes with Google will get them just about anything they need.

But it doesn't really sound like you're trying to lock down highly sensitive data here. So....

Turn on your macro recorder (Tools > Macro > Record New Macro) and enable whatever protection you want.

Observe the code that was generated by pressing [Alt] + [F11].

Post your code here for any help you need cleaning it up or understanding it.



[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ 181-2886 before posting.
 
Just to expand that, the True in Tony's code refers to a parameter in .Protect. NoReSet.

It is Boolean so it can be either True, or False.

If set as True (as In Tony's example), then the current values of the formfields are preserved.

If set as False, the formfield values are cleared.

The default is False.

faq219-2884

Gerry
My paintings and sculpture
 
Thank you Gerry. You know I can be a bit sloppy in code I post sometimes :). I assumed after running a macro on a new document that True would do no harm, but False might but I should, of course, have explained it.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
I mentioned it because in the OP, there is this line:

"because it is a template that has a couple of macros that insert text into specific fields."

That is, there is something that is putting text into the formfields. Now, it looks like the OP would want those values to persist...but I certainly do not know that for sure. As we have both seen a number of threads here, and elsewhere, that ask about formfield values clearing when they do not want them to (or the other way around), I thought it may be worthwhile to mention what your "True" refers to.

faq219-2884

Gerry
My paintings and sculpture
 
I thank both of you for your assistance. I was able to work it out/.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top