WD2000: How to Retain Information Typed Into a Form Field When You Protect a FormID: q191028
|
This article describes methods that allow you to do the following:
Microsoft provides programming examples for illustration only, without
warranty either expressed or implied, including, but not limited to, the
implied warranties of merchantability and/or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language being demonstrated and the tools used to create and debug
procedures. Microsoft Support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to
provide added functionality or construct procedures to meet your specific
needs. If you have limited programming experience, you may want to contact
the Microsoft fee-based consulting line at (800) 936-5200. For more
information about the support options available from Microsoft, please see
the following page on the World Wide Web:
http://www.microsoft.com/support/supportnet/refguide/
Sub ProtectForm()
' ******************************************
' ProtectForm Macro.
' Toggles protection for the active document
' when the Protect Form button on the forms
' toolbar is clicked.
' ******************************************
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
Else
ActiveDocument.Unprotect Password:=""
End If
End Sub
Sub ToolsProtectUnprotectDocument()
' ******************************************
' ToolsProtectUnprotectDocument Macro
' Sets protection for the active document
' when Protect Document or Unprotect Document
' is clicked on Tools menu
' ******************************************
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
Else
ActiveDocument.Unprotect Password:=""
End If
End Sub
Sub ProtectNoReset()
Dim pDoc As Dialog
Dim x As Integer
On Error GoTo ProtectNoResetErr
' If the document is protected,
If ActiveDocument.ProtectionType <> wdNoProtection Then
' Unprotect the document.
ActiveDocument.Unprotect
End If
' Display the Protect Dialog box.
Set pDoc = Dialogs(wdDialogToolsProtectDocument)
x = pDoc.Display
' If Cancel was chosen, exit this procedure.
If x = 0 Then Exit Sub
' Protect the document.
ActiveDocument.Protect Password:=pDoc.DocumentPassword, _
NoReset:=True, Type:=2
ProtectNoResetErr: 'NOTE: This line MUST be left aligned.
If Err <> 0 Then MsgBox Err.Description
End Sub
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
Sub FormsSpellCheck()
' 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
' 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
Q163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: kbmacro vba
Keywords : kbdta wd2000
Version : WINDOWS:2000
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 19, 1999