Excel VBO unlock worksheet

vandede

New Member
I am currently looking for a VBO to unlock worksheets in a Excel file. I found the lock workbook vbo and tried to amend it for the worksheet lock function but could not seem to do so. Does someone have such a VBO and could help me (especially with the code part).

Thank you in advance
 

VJR

Well-Known Member
Hi vandede,

The Protect Workbook action won't work as it is for a workbook and you want it to a worksheet. Is it correct?
Also did you mean unprotect when you meant unlock?

If so you will need to make a copy of any of the existing actions and then make the changes as below

Code:
Dim sw As Object
Dim ss As Object
Dim excel, sheet As Object

sw = GetWorkbook(Handle, Source_Workbook)
ss = GetWorksheet(Handle, Source_Workbook, Source_Worksheet)

sw.Activate()
ss.Activate()   'the ss object can also be directly used below to unprotect the sheet without activating it

excel = ss.Application
sheet = excel.ActiveSheet

sheet.Unprotect ("password")      'where "password" is the actual password for the sheet and a variable can also be passed from the
'calling Process to make it more dynamic
 
Last edited:

vandede

New Member
@VJR thank you for your help! Really saved me many headaches.

Just as an update for other people that want to use the code above. It was functional for me and works now. Apart from the naming of the variables I only had to change the last line by adding brackets around password.

sheet.Unprotect (Password)
 

VJR

Well-Known Member
You're right Vandede. I've posted the above code without using Blue Prism and it is true that Bp throws an error when a bracket is not used for a function. I've now modified the above code so that it can be used. Thanks.
 

Deva393

Member
You're right Vandede. I've posted the above code without using Blue Prism and it is true that Bp throws an error when a bracket is not used for a function. I've now modified the above code so that it can be used. Thanks.


Hi VJR

How to protect workbook with password
 

dedika

New Member
Hello guys,

I'm looking for help.

I have a problem with unlocking two tables (finance analyze).

Few times I unlocked different tables with this code:

Sub PasswordBreaker()

'Breaks worksheet password protection.

Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If ActiveSheet.ProtectContents = False Then
MsgBox "One usable password is " & Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
Exit Sub
End If
Next: Next: Next: Next: Next: Next
Next: Next: Next: Next: Next: Next
End Sub

With this two tables I replaced:
Line 12, replace "ActiveSheet" with "ThisWorkbook"
Line 15, replace "ActiveSheet.ProtectContents" with "ThisWorkbook.ProtectStructure"

and got a message One usable password, as I got before with other tables.

Does any know how to unlock this two tables?
 

Attachments

  • 1.zip
    547.9 KB · Views: 11
  • 2.zip
    512.3 KB · Views: 2

Carlos gomez

New Member
Hello I am New user in Blueprism, I can read a collection from a workbook with a sheet protected with password, but when i tried to save the collection The stage generate an error. Its possible Unlock the Sheet1 in Blueprism?. I found this information but work with a code and i think that is for expert user. Thank you
 

Attachments

  • Capture.JPG
    50.4 KB · Views: 30
Top