strange happenings with document protection code

K

kill_beast

So I have a Word document with Form Field protection. It has code for both
Document_Close and Document_Open.

Both use this to turn off and turn back on the protection:

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="<password>"
End If

....and then...

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="<password>"

In between these statements, I have some code that attempts to change the
font of some form fields, but for some reason, the Document_Open sub
procedure doesn't work, specifically because it says that form protection is
on. Basically, my Unprotect section isn't working on Document_Open. It
does, however, work fine on my Document_Close.

What could be the reason for this? I check the passwords to make sure I
hadn't fat fingered something, and I haven't.

Any ideas?

Thanks!
 
K

kill_beast

Furthermore,

When the document is already open, and I run the Document_Open sub procedure
from the Visual Basic Window, it works fine. It just doesn't seem to work
when actually opening the document.
 
K

kill_beast

One more thing I should've mentioned,

The Unprotect code doesn't work when passwords are all set to "" either.

Just on the Document_Open procedure, and only when the document is actually
opening (I can manually run the procedure and it works fine).
 

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