Microsoft Office Tutorials and References
In Depth Information
Using Forms Protection
View the Appendix to learn how to store this procedure
in the ThisDocument module.
Option explicit¶
' * * * * *¶
Private Sub Document_Open()¶
End Sub¶
Using Forms Protection
Generating an entire document from scratch can be a challenge. Somewhat
easier is the method of protecting the file as a Word form (don’t confuse this
with a UserForm) with a password by using Tools | Protect document. The
'Document_Open', 'Auto Open', 'Document_New', or 'AutoNew' procedure can be
built to remove the protection and do any other preparatory work (such as
removing a message to the user at the beginning of the document about
activating macro security), as this sample code demonstrates.
View the Appendix to learn how to store this procedure
in a Standard module.
Sub RemoveProtection()¶
ActiveDocument.Unprotect "test"¶
'Remove macro message¶
End Sub¶
The only real problem with this approach is that it is not 100% secure. Anyone
can, from a blank document, use Insert | File and choose the protected
document to open it in an unprotected state, even if it has been password
If the main concern is to restrict the user from accidentally working with the
file without the macros, then form field protection is certainly an acceptable
Macros in Files Opened by Code
A related problem is macro security for other documents your code might need
to open. If the user has set macro security to "Medium", a prompt appears if
any files opened by the code contain macros. This can be irritating to the user if
Search JabSto ::

Custom Search