What is the VBA for protecting a document

P

Patti

We have created a document thatputs in demographics automatically. In order
to make this work, the document cannot be protected. After the demographics
are fed in, I need to protect the document to make the rest of the form
usable to our staff. I would like to enter VBA code into an autoopen macro
that already feeds the demographics into the doc. My boss does not want staff
to be able to touch anything but the fields. Thanks for any assistance.
Patti
 
W

Word Heretic

G'day "Patti" <[email protected]>,

I would be happy to provide this service commercially if you need a
solution.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Patti reckoned:
 
B

Ben M

I thought this was a forum to help people, not to peddle your business. You
should be ashamed Steve Hudson.
 
B

Ben M

Patti,

Here is some code that I had used to protect/unprotect a document. You can
also use a password as I have done. I have also checked if the document is
protected before I unprotect it etc.

Hope this free help is of use.


' // --------------------------------- //
' // UnprotectDocument //
' // --------------------------------- //

Sub UnprotectDocument()
On Error Resume Next
If ActiveDocument.ProtectionType = wdNoProtection Then
Debug.Print
Else
ActiveDocument.Unprotect Password:="password"
End If
End Sub

' // --------------------------------- //
' // ProtectDocument //
' // --------------------------------- //

Sub ProtectDocument()
On Error Resume Next
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="password"
Else
Debug.Print
End If
End Sub

The just call the sub you want.

Call ProtectDocument 'example how to call
 
P

Patti

Thank you Ben. It works perfectly. I appreciate your assistance and that you
did not charge me!
Patti
 
D

Doug Robbins

While your subject of your post just talked about protecting the document,
the body of it talked about a macro to import the demographics. It was
almost certainly that part to which Steve was referring.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
W

Word Heretic

G'day "Ben M" <[email protected]>,

Ok, so you've done 10% of the job - now finish it.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Ben M reckoned:
 
W

Word Heretic

G'day "Patti" <[email protected]>,

So why did you ask for it?


Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Patti reckoned:
 
B

Ben M

Patti, I am glad this works for you.

Word Heretic... For someone that charges money to do VBA, you sure have
problems reading plain English.

Perhaps you should re-read the question (and maybe read it again). You
might then realise that the demographic import has already been done,
leaving the original question on how to protect/unprotect the document.

It's common for people requesting *help* to set the scene in what they are
trying to achieve. This is simply what Patti did.

What part of "We _have created_ a document that puts in demographics
automatically" did you not understand??

Kind Regards, Ben
 

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