Template spell check and security

H

Helen

I have a large number of template forms with fill-in fields. I've embedded a
macro (below) that allows the document to be unprotected, spell checked, then
reprotected using just a single toolbar button. The manager of the division
now wants people to be unable to manually unprotect any template to stop
unauthorized tampering with the boilerplate, but still wants to be able to
spell check. I've been passwording the unprotect function, but that disables
the spell check macro. Can I modify the macro to automate the unprotect,
enter password, spell check, and invisibly reprotect with the password?

Thanks!

The code:
Sub FormsSpellCheck()
'
' FormsSpellCheck Macro
' Macro created 4/28/2004 by helenp

' If document is protected, unprotect it
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=" "
End If

' Set the language for the document.
Selection.WholeStory
Selection.LanguageID = wdEnglishUS
Selection.NoProofing = False

' Perform Spelling/Grammar check.
' If Options.CheckGrammarWithSpelling = True Then
' ActiveDocument.CheckGrammar
' Else
ActiveDocument.CheckSpelling
' End If

' Reprotect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End If

End Sub

Sub ToolsProtectUnprotectDocument()
' Macro written by helenp 11/18/2004
' Allows document to be unprotected and reprotected without resetting fields
Dim oDoc As Document
Set oDoc = ActiveDocument

On Error GoTo ErrMess
If oDoc.ProtectionType = wdNoProtection Then
With Dialogs(wdDialogToolsProtectDocument)
..noreset = True
..Show
End With
Else
oDoc.Unprotect
End If
Exit Sub

ErrMess:
MsgBox Err.Description, blInformation

End Sub

Sub ProtectForm()
' Macro written by helenp 11/18/2004
' Allows document to be unprotected and reprotected without resetting fields

If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
Else
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True
End If


End Sub
 
C

Charles Kenyon

See http://www.mvps.org/word/FAQs/MacrosVBA/SpellcheckProtectDoc.htm.
There are instructions at the end on how to handle password protected
documents. Note that you will also want to password protect your code.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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