Use of multiple passwords in a single macro

K

Ken White

Hi, and thanks for your anticipated help.

I use a macro that allows Spell Check to work in locked forms that are
protected by a password. Here is the line from the macro that gives the
password that unlocks the form: oDoc.Unprotect Password:="mazie"

I have hundreds of forms and many of them use a different password than the
one given above. My question: How do I add another password to the example
given above so that the one macro will open locked forms with different
passwords? Do I just write : ="mazie"or"toys"

I really appreciate your help, and all the tremendous knowledge you people
share with us. Thanks!
 
J

Jonathan West

Hi ken,

You can only try one password at a time. But if you have the wrong password,
the Unprotect method will throw an error. You can trap the error in an error
handler and then try again.


Try something like this

Dim strPassword as String
strPassword = "mazie"
Or Error Goto Errhandle
oDoc.Unprotect Password:="mazie"
Exit Sub

Errhandle:
If strPassword = "mazie" Then
strPassword = "toys"
Err.Clear
Resume
Else
MsgBox "Could not find the right password"
End If
 
D

Doug Robbins

Have you tried what I suggested in response to your identical post in
another newsgroup yesterday?

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - 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