Sunday, 30 December 2012

Unprotecting a protected Worksheet


I don't advocate it, but this is a script to break the password on a password protected Excel worksheet.


'Break the Password on a locked Worksheet
Sub UnprotectSheet()
'Break Protection on a Worksheet.
    Dim funnet As Boolean: Dim tekst As String
    Dim i As Integer: Dim j As Integer: Dim k As Integer
    Dim l As Integer: Dim m As Integer: Dim N As Integer: Dim o As Integer: Dim p As Integer
    Dim gmlStatusLinje As Variant: Dim gmlTid As Variant
    Dim oldCalculation As Integer
    On Error Resume Next

    oldCalculation = Application.Calculation

    Application.Calculation = xlManual
    Application.ScreenUpdating = False
    gmlStatusLinje = Application.DisplayStatusBar
    Application.DisplayStatusBar = True
    gmlTid = Now()
    Application.StatusBar = Format(Now() - gmlTid, "hh.mm.ss")
    ActiveSheet.Protect ("")
    funnet = ActiveSheet.Unprotect("")

    If Not funnet Then

   For i = lower To upper
  tekst = Chr(i)
  funnet = ActiveSheet.Unprotect(tekst)
  If funnet Then Exit For
   Next
    End If
    Application.StatusBar = Format(Now() - gmlTid, "hh.mm.ss")
    If Not funnet Then
   For i = lower1 To lower2
  For j = lower To upper
 tekst = Chr(i) + Chr(j)
 funnet = ActiveSheet.Unprotect(tekst)
 If funnet Then Exit For
  Next
  Application.StatusBar = Format(Now() - gmlTid, "hh.mm.ss")
  If funnet Then Exit For
   Next
    End If
    If Not funnet Then
   For i = lower1 To lower2: For j = lower1 To lower2
 For k = lower To upper
tekst = Chr(i) + Chr(j) + Chr(k)
funnet = ActiveSheet.Unprotect(tekst)
If funnet Then Exit For
 Next
 Application.StatusBar = Format(Now() - gmlTid, "hh.mm.ss")
 If funnet Then Exit For
  Next
  If funnet Then Exit For
   Next
    End If
    If Not funnet Then
   For i = lower1 To lower2: For j = lower1 To lower2: For k = lower1 To lower2
For l = lower To upper
 tekst = Chr(i) + Chr(j) + Chr(k) + Chr(l)
 funnet = ActiveSheet.Unprotect(tekst)
 If funnet Then Exit For
Next
Application.StatusBar = Format(Now() - gmlTid, "hh.mm.ss")
If funnet Then Exit For
 Next
 If funnet Then Exit For
  Next
  If funnet Then Exit For
   Next
    End If
    If Not funnet Then
   For i = lower1 To lower2: For j = lower1 To lower2: For k = lower1 To lower2: For l = lower1 To lower2
 For m = lower To upper
 tekst = Chr(i) + Chr(j) + Chr(k) + Chr(l) + Chr(m)
 funnet = ActiveSheet.Unprotect(tekst)
 If funnet Then Exit For
 Next
 Application.StatusBar = Format(Now() - gmlTid, "hh.mm.ss")
 If funnet Then Exit For
Next
If funnet Then Exit For
 Next
 If funnet Then Exit For
  Next
  If funnet Then Exit For
   Next
    End If
    If Not funnet Then
   For i = lower1 To lower2: For j = lower1 To lower2: For k = lower1 To lower2: For l = lower1 To lower2: For m = lower1 To lower2
 For N = lower To upper
tekst = Chr(i) + Chr(j) + Chr(k) + Chr(l) + Chr(m) + Chr(N)
funnet = ActiveSheet.Unprotect(tekst)
If funnet Then Exit For
 Next
 Application.StatusBar = Format(Now() - gmlTid, "hh.mm.ss")
 If funnet Then Exit For
 Next
 If funnet Then Exit For
Next
If funnet Then Exit For
 Next
 If funnet Then Exit For
  Next
  If funnet Then Exit For
   Next
    End If
    If Not funnet Then
   For i = lower1 To lower2: For j = lower1 To lower2: For k = lower1 To lower2: For l = lower1 To lower2: For m = lower1 To lower2: For N = lower1 To lower2
For o = lower To upper
 tekst = Chr(i) + Chr(j) + Chr(k) + Chr(l) + Chr(m) + Chr(N) + Chr(o)
 funnet = ActiveSheet.Unprotect(tekst)
 If funnet Then Exit For
Next
Application.StatusBar = Format(Now() - gmlTid, "hh.mm.ss")
If funnet Then Exit For
 Next
 If funnet Then Exit For
 Next
 If funnet Then Exit For
Next
If funnet Then Exit For
 Next
 If funnet Then Exit For
  Next
  If funnet Then Exit For
   Next
    End If
    If Not funnet Then
For i = lower1 To lower2: For j = lower1 To lower2: For k = lower1 To lower2: For l = lower1 To lower2
For m = lower1 To lower2: For N = lower1 To lower2: For o = lower1 To lower2
For p = lower To upper
tekst = Chr(i) + Chr(j) + Chr(k) + Chr(l) + Chr(m) + Chr(N) + Chr(o) + Chr(p)
funnet = ActiveSheet.Unprotect(tekst)
If funnet Then Exit For
Next
 Application.StatusBar = Format(Now() - gmlTid, "hh.mm.ss")
 If funnet Then Exit For
Next
If funnet Then Exit For
 Next
 If funnet Then Exit For
 Next
 If funnet Then Exit For
Next
If funnet Then Exit For
 Next
 If funnet Then Exit For
  Next
  If funnet Then Exit For
   Next
    End If
    Application.ScreenUpdating = True
MsgBox "Password broken"
    Application.StatusBar = False
    Application.DisplayStatusBar = gmlStatusLinje
    Application.Calculation = oldCalculation
End Sub


No comments:

Post a Comment