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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use VBA to lock multiple sections in a Word Doc

Status
Not open for further replies.

BakeMan

Programmer
Jul 24, 2002
129
US
Does anyone know how I can use VBA to protect multiple sections on a Word doc to allow only form fields. I have several sections in a template that I do not want changed. Other sections are meant to be changed. I currently have these in different sections in the template. I have protected these using the "tools --> Protect document" menu option. I then select protect document for "Forms". Word then gives me a list of sections that I can check or uncheck to have protected. I have written a process in VBA that will allow the user to update certain pieces of the protected sections. I am using

ActiveDocument.Unprotect Password:="password"

to unprotect the document. This works great. But when I want to reprotect the document I can't list every section. I seem to either get the whole document protected

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, Password:="password"

or only one section

ActiveDocument.Sections(3).Protect Type:=wdAllowOnlyFormFields, Password:="password"

does anyone know how I can protect several sections at once.

Thank you in advance,

BAKEMAN [pimp]
 
I found the answer!! you have to describe each section before protecting the document.

ActiveDocument.Sections(1).ProtectedForForms = False
ActiveDocument.Sections(2).ProtectedForForms = False
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Sections(4).ProtectedForForms = False
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, Password:="password"

Thanks to anyone looking for the solution. I hope this will help someone.

BAKEMAN [pimp]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top