Word 2002 macro to protect all sections except most recent

G

Greg

I'm creating a Word 2002 document and I'd like to be able to write a
macro that will protect previous sections and start a new unprotected
section. I have tried several ways of doing this, but I am not
familiar enough with VBA to know the ins and outs of VB security.
Several users will be entering information (plain text) into this
document so I want a macro which will create a new section when the
user runs the macro, protects the section they had just worked on (and
possibly all previous sections if they need to be re-protected), and
saves the document. The idea is that only someone with the password
can edit work which has already been entered and is currently
protected to prevent tampering.

I have played around with this but I do not know enough VB to either
protect the newest section created or to possibly unprotect all
sections and reprotect all but the last section.

Any help you might be able to give towards a solution will be greatly
appreciated, even if the answer ends up being that it's not possible.

Thanks!
Greg
 
M

Mark Tangard

Hi Greg,

First, just FYI, this is emphatically not what 'protection' is
about. Protecting a document or section enables it to act as a
form, in which static text is not editable and only "formfields"
can receive input. It has nothing to do with security.

That said, it's *almost* possible to do what you want:

Selection.EndKey wdStory
Selection.InsertBreak wdSectionBreakNextPage
With ActiveDocument
.Sections(.Sections.Count).ProtectedForForms = False
.Sections(.Sections.Count - 1).ProtectedForForms = True
End With

Only problem is, you can't add a password to a multi-section
form some of whose sections are unprotected. THe Password:=
parameter is available only to the .Protect method, which
protects an entire document.

Maybe there's another way? Do the users need to *see* the
other sections? If not, maybe an AutoOpen macro in the document
that immediately saves its content to another file (passworded)
and erases it from the opened file? Sounds pretty convoluted,
but questions like this usually do have strange solutions, if
any. (This suggestion wouldn't work if any of your users are
savvy enough to know how to supress macro execution, and in
fact wouldn't work with macro security set to the default of
High either....)
 
L

Lars-Eric Gisslén

Mark,

I don't understand what you mean. We have several documents with protected
and unprotected sections and the document is password protected. We have for
instance a contract template for one of the big oil companies that the sales
poeple uses. Sections with legal texts can't be changed by the sales people
while other sections are unprotected so they can change the text for each
client. A few protected sections has FormFields while other procted sections
are just dead text. Unprotected sections can be edited just like an
unprotected document.

Regards,
Lars-Eric
 
M

Mark Tangard

Lars-Eric,

Aagh. You're right. The limitation isn't with password protecting
the document. I also misread Greg's post and thought he implied he
wanted a macro *IN* the same document, which I'm pretty sure can't
be done. (His sectons have no formfields, which is the only way
one could run a macro from within the protected form.)
 
G

Greg

Thanks for your help Marc and Lars.

I did get it working, though the document has to be "prepared" ahead
of time. The code is:

ActiveDocument.Unprotect Password:="Password"
Selection.EndKey wdStory
Selection.InsertBreak wdSectionBreakContinuous
With ActiveDocument
'.Sections.ProtectedForForms = False
.Sections(.Sections.Count - 1).ProtectedForForms = True
End With
ActiveDocument.Protect Password:="", NoReset:=False, Type:= _
wdAllowOnlyFormFields
ActiveDocument.Save


To prepare the document, you must first insert a section break,
protect the first section, and save the document. Now, anybody that
works on it will only be able to work in the new section and run the
macro, which protects that section, saves the document, and creates a
new unprotected section.

Works a charm, thanks guys!

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top