how can I know if a workbook is locked?
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. guilhaume wrote: 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 when 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 If condition and tries to unlock While debuging, I saw that pass has the following value: "********" what can I do? Guilhaume -- guilhaume ------------------------------------------------------------------------ guilhaume's Profile: http://www.excelforum.com/member.php...o&userid=12009 View this thread: http://www.excelforum.com/showthread...hreadid=319779 -- Dave Peterson |
how can I know if a workbook is locked?
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... ;) -- guilhaum ----------------------------------------------------------------------- guilhaume's Profile: http://www.excelforum.com/member.php...fo&userid=1200 View this thread: http://www.excelforum.com/showthread.php?threadid=31977 |
how can I know if a workbook is locked?
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 guilhaume wrote: 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... ;)) -- guilhaume ------------------------------------------------------------------------ guilhaume's Profile: http://www.excelforum.com/member.php...o&userid=12009 View this thread: http://www.excelforum.com/showthread...hreadid=319779 -- Dave Peterson |
All times are GMT +1. The time now is 11:14 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com