Protecting Header/Footer in Word 2007

green

Registered User
Local time
Today, 09:38
Joined
Dec 23, 2009
Messages
20
I am trying to figure out how to protect the header and footer of a company letterhead document using vba. How do I reference those parts of the document specifically and leave the rest of the document available for use by employees? Thanks in advance.
 
Thanks for your response, Trevor G. I am really looking to use vba coding to accomplish the protection. I have a form with loads on open. I use that to flood bookmarks. Now I want to lock the header and footer using code.
 
Ok thats fair enough, so why not record a macro when going through the steps of the link I sent, then you will have the code to add to your document.
 
I wasn't aware recording a macro created code. I'll check to see what I can figure out.
 
Just because I was curious. I tried recording the steps into a macro and it was fine until I acutally protected the document. But I looked at the help and it pretty clear how to to setup the protection using VBA.
 
Always worth looking to record a MACRO with a planned action then look a the code and use the debugger and help when needed.

Well done for figuring this out.

Perhaps posting the code to this thread will help others.
 
Thanks Trevor G and kelvray for your input. I was able to use the macro recorder to get part of what I needed and then added a line code to complete it. The solution is as follows:

1. Add section break at the top of the document. By default, this associates the first page header/footer with Section 1. (That is all I needed to protect.)
2. Include the following code lines:
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = False
ActiveDocument.Protect wdAllowOnlyFormFields
3. If you plan to use the same document again, it is necessary to unlock the document before edits are possible. (Passwords can be used both with .Protect and .Unprotect.)
If ActiveDocument.ProtectionType <> wdNoProtection Then ActiveDocument.Unprotect
 

Users who are viewing this thread

Back
Top Bottom