OK, I think I have the measure of it
Try the following. You will need to ensure that the macro uses the correct
language (English UK in the example) and you must put all the possible
passwords in the password list defined
sPasswordList = "pear¦apple¦banana¦"
The list is checked from last to first. The final ¦ ensures that a form is
checked against a nul password first.
The same password used to open the form is used to protect it again.
Sub SpellCheckForm()
Dim i As Integer
Dim bProtected As Boolean
Dim sPasswordList As String
Dim vPass As Variant
Dim sPassword As String
sPasswordList = "pear¦apple¦banana¦" 'List of all passwords
vPass = Split(sPasswordList, "¦") 'split the list at the indicated character
For i = UBound(vPass) To 0 Step -1 'try each item in the list from right to
left
If ActiveDocument.ProtectionType <> wdNoProtection Then
'check if the form is actually protected
bProtected = True 'and if it is set a flag
On Error Resume Next 'trap the error of using the wrong password
'Unprotect the document using.
ActiveDocument.Unprotect Password:=vPass(i)
'If the document has been unprotected note the password used
If ActiveDocument.ProtectionType = wdNoProtection Then
sPassword = vPass(i)
End If
End If
Next i
'spell check the form
For i = 1 To ActiveDocument.FormFields.Count
ActiveDocument.FormFields(i).Select
#If VBA6 Then
Selection.NoProofing = False
#End If
Selection.LanguageID = wdEnglishUK
Selection.Range.CheckSpelling
Next
'If the macro unlocked the form, reprotect it
'using the password that opened it.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=sPassword
End If
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>