several passwords for excel workbooks

G

guilhaume

Hi all
I get several thousand of excel files which workbooks are locked
I already asked and get a solution on how unlock them with a V
program

but my problem is following:
there are two possible passwords for the excel files

I tryed to put the two unlocking lines one after the other:
bk.Unprotect Password:="toto"
bk.Unprotect Password:="tata"

but I get an error, as when I'm treating file which password is "tata"
an error message is displayed and the execution of the program stops

Is there an equivalent to the java try-catch ?
(i was thinking to do something like:
try{ bk.Unprotect Password:="toto"}
catch(Exception e){bk.Unprotect Password:="tata"}
)

by the way how can I know if an Excel file has it workbook protected?

Thanks for all

guilhaum
 
R

Ron de Bruin

You can use On Error Resume Next like this

Sub test()
On Error Resume Next
ActiveWorkbook.Unprotect "toto"
ActiveWorkbook.Unprotect "tata"
On Error GoTo 0
End Sub
 
G

guilhaume

Thanks, it seems to work fine!

How can I know if a workbook is locked (not to try to treat them whe
they are unlocked)
I tried to do:
Dim pass As String
pass= currentWorkbook.Password
If pass <> "" Then
treatment.....
End If
But even if the workbook is unlocked, the program passes into the I
condition and tries to unlock
While debuging, I saw that pass has the following value: "********"

what can I do?

Guilhaum
 

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