Having problems protecting a word document with VBA

G

grixnair

We are in the process of converting to Word 2007 and some of my users
are complaining about the number of clicks required to protect and
unprotect their documents, so I am trying to add a button to the Quick
Access Toolbar that will change the protection. So far I am able to
get the unprotect to work, but I am getting an error when trying to
protect it.

The macro I have mapped to the button is this:

Sub ChangeProtection()
If ActiveDocument.ProtectionType <> wdAllowOnlyFormFields Then
ActiveDocument.Protect wdAllowOnlyFormFields, True
Else
ActiveDocument.Unprotect
End If
End Sub

I use similar code in some of the templates I've created without any
problems, but calling the code from a button on the Quick Access
Toolbar doesn't work. I get an error message box that doesn't provide
any information at all.

I tried putting a breakpoint in the code so that I could step through
it but it gives me the error without hitting my breakpoint. So I
created another macro to just do the Protect part that gets me a
warning message box that has a message of "Arguement not optional"

Sub Protect()
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True
End If
End Sub

Any help or suggestions would be greatly appreciated.

Dan
 
J

Jay Freedman

I don't know what problems you're running into here, but the macro is
unnecessary. The old Lock icon is still available to put on the QAT.

In the Customize dialog, select the category Commands Not in the Ribbon. You'll
find the Lock command there (or in All Commands), and it even has the same icon
as in 2003.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 

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