Multiple passwords in VBA macro

K

Ken Curtis

I use forms protected by password. I added one of your macros that allows MS
Spellcheck to run in protected forms. The macro, obviously, uses a password.
Here is the script: Password:="mazie"

If I want to use more than one password, do I simply write:
Password:="maxie","apple","banana" etc, or is it rather more difficult that
this?
 
G

Graham Mayor

You can only use one password for one document. The form may not need to be
protected with a password, which in any case forms only a very weak barrier
to user access.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Ken Curtis

Yes, I understand "one password for one form". Maybe a little more detail
would help me to explain.
As you know, when a form is protected, tools like Spellcheck are not
available. I downloaded and installed a remarkable macro to get around this
issue, and added it to the Word tool bar on a button. We have several
hundred forms, and they are all protected (we need this many forms because we
are a Social Service Agency protecting Children as Crown Wards ... and there
are endless documents to be filled). This one macro (an option explicit) is
accessable to all protected forms opened by Word. So, can form one be
protected with the password "one" and another form be protected with the
password "banana". Different passwords on a few different forms, but all
written into the same macro?
Thanks,
Ken
 
K

Ken Curtis

Mr. Mayor, your wrote: "The form may not need to be
protected with a password, which in any case forms only a very weak barrier
to user access". Is there a better / stronger way of protecting a form?
 
G

Graham Mayor

No - form protection is very weak and concerned only with protecting from
accidental changes - http://www.gmayor.com/Remove_Password.htm .
I'll have a look at your other issue now I see what the problem is.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
C

Cindy M.

Hi Graham,
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?"

What is the character code of the symbol you're using to separate the various
words? I'm seeing one thing in my newsreader, another in the "Reply" window,
and I'm pretty sure none of them are correct :)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
G

Graham Mayor

The character I used was ALT+0166 from the numeric keypad. The character
should not be especially critical as long as it is the same throughout.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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