how can I know if a workbook is locked?

  • Thread starter Thread starter guilhaume
  • Start date Start date
G

guilhaume

hi all
I have a lot of excel file to unlock with a VB program
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
unlocking_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
 
Workbooks can be locked in a few different ways.

Do you mean that you have:

1. Worksheets that are portected via tools|protection?
2. The workbook is protected via Tools|protection?
3. The workbook is protected from opening via File|saveas|tools|...?
4. The VBA project is protected tools|vbaproject properties?

Each would have a different response.

And you may want to post a little more specifics (not a workbook) just for more
background.
 
the workbook is locked by the following way:

tools -> protection -> protect the workbook

(I think it is that , in my case the menu options are in french... ;)
 
You could just try unprotecting, then check to see if you did it successfully:

Option Explicit
Sub testme01()

Dim wkbk As Workbook
Set wkbk = ActiveWorkbook

If wkbk.ProtectWindows _
Or wkbk.ProtectStructure Then
On Error Resume Next
wkbk.Unprotect Password:="aaa"
On Error GoTo 0
If wkbk.ProtectWindows _
Or wkbk.ProtectStructure Then
MsgBox "still protectected!"
Else
MsgBox "WooHoo, Found a password"
End If
Else
MsgBox "Not protected"
End If
End Sub


You may want to take a look at J.E. McGimpsey's code that will unprotect both
the workbook and worksheets:
http://www.mcgimpsey.com/excel/removepwords.html
 

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

Back
Top