Guest User

Untitled

a guest
Dec 18th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.16 KB | None | 0 0
  1. ub TestPasswordLoop()
  2.  
  3. Dim directory As String, fileName As String, i As Variant, wb As Workbook
  4. Application.DisplayAlerts = False
  5. Application.ScreenUpdating = False
  6.  
  7. Dim security As MsoAutomationSecurity
  8. security = Application.AutomationSecurity
  9. Application.AutomationSecurity = msoAutomationSecurityForceDisable
  10.  
  11. directory = "C:UserssethDesktopFiles for Testing"
  12. fileName = Dir(directory & "*.xl??")
  13.  
  14. i = 0
  15. Do While fileName <> vbNullString
  16. On Error Resume Next
  17. 'Set wb = Workbooks.Open(fileName:=directory & fileName)
  18. Set wb = Workbooks.Open(fileName:=directory & fileName, _
  19. UpdateLinks:=0, _
  20. IgnoreReadOnlyRecommended:=True, _
  21. Notify:=False, _
  22. CorruptLoad:=xlNormalLoad)
  23.  
  24. Call AllInternalPasswords 'this code is below
  25. wb.Close True
  26. i = i + 1
  27. Application.StatusBar = "Files Completed: " & i
  28. fileName = Dir()
  29. Loop
  30.  
  31. Application.AutomationSecurity = security
  32. Application.StatusBar = False
  33. Application.ScreenUpdating = True
  34. Application.DisplayAlerts = True
  35. MsgBox "Complete"
  36.  
  37. End Sub
  38.  
  39. Public Sub AllInternalPasswords()
  40. ' Breaks worksheet and workbook structure passwords. Bob McCormick
  41. ' probably originator of base code algorithm modified for coverage
  42. ' of workbook structure / windows passwords and for multiple passwords
  43. '
  44. ' Norman Harker and JE McGimpsey 27-Dec-2002 (Version 1.1)
  45. ' Modified 2003-Apr-04 by JEM: All msgs to constants, and
  46. ' eliminate one Exit Sub (Version 1.1.1)
  47. ' Reveals hashed passwords NOT original passwords
  48.  
  49. Application.DisplayAlerts = False
  50. 'Application.ScreenUpdating = False
  51.  
  52. Const DBLSPACE As String = vbNewLine & vbNewLine
  53. Const AUTHORS As String = DBLSPACE & vbNewLine & _
  54. "Adapted from Bob McCormick base code by" & _
  55. "Norman Harker and JE McGimpsey"
  56. Const HEADER As String = "AllInternalPasswords User Message"
  57. Const VERSION As String = DBLSPACE & "Version 1.1.1 2003-Apr-04"
  58. Const REPBACK As String = DBLSPACE & "Please report failure " & _
  59. "to the microsoft.public.excel.programming newsgroup."
  60. Const ALLCLEAR As String = DBLSPACE & "The workbook should " & _
  61. "now be free of all password protection, so make sure you:" & _
  62. DBLSPACE & "SAVE IT NOW!" & DBLSPACE & "and also" & _
  63. DBLSPACE & "BACKUP!, BACKUP!!, BACKUP!!!" & _
  64. DBLSPACE & "Also, remember that the password was " & _
  65. "put there for a reason. Don't stuff up crucial formulas " & _
  66. "or data." & DBLSPACE & "Access and use of some data " & _
  67. "may be an offense. If in doubt, don't."
  68. Const MSGNOPWORDS1 As String = "There were no passwords on " & _
  69. "sheets, or workbook structure or windows." & AUTHORS & VERSION
  70. Const MSGNOPWORDS2 As String = "There was no protection to " & _
  71. "workbook structure or windows." & DBLSPACE & _
  72. "Proceeding to unprotect sheets." & AUTHORS & VERSION
  73. Const MSGTAKETIME As String = "After pressing OK button this " & _
  74. "will take some time." & DBLSPACE & "Amount of time " & _
  75. "depends on how many different passwords, the " & _
  76. "passwords, and your computer's specification." & DBLSPACE & _
  77. "Just be patient! Make me a coffee!" & AUTHORS & VERSION
  78. Const MSGPWORDFOUND1 As String = "You had a Worksheet " & _
  79. "Structure or Windows Password set." & DBLSPACE & _
  80. "The password found was: " & DBLSPACE & "$$" & DBLSPACE & _
  81. "Note it down for potential future use in other workbooks by " & _
  82. "the same person who set this password." & DBLSPACE & _
  83. "Now to check and clear other passwords." & AUTHORS & VERSION
  84. Const MSGPWORDFOUND2 As String = "You had a Worksheet " & _
  85. "password set." & DBLSPACE & "The password found was: " & _
  86. DBLSPACE & "$$" & DBLSPACE & "Note it down for potential " & _
  87. "future use in other workbooks by same person who " & _
  88. "set this password." & DBLSPACE & "Now to check and clear " & _
  89. "other passwords." & AUTHORS & VERSION
  90. Const MSGONLYONE As String = "Only structure / windows " & _
  91. "protected with the password that was just found." & _
  92. ALLCLEAR & AUTHORS & VERSION & REPBACK
  93. Dim w1 As Worksheet, w2 As Worksheet
  94. Dim i As Integer, j As Integer, k As Integer, l As Integer
  95. Dim m As Integer, n As Integer, i1 As Integer, i2 As Integer
  96. Dim i3 As Integer, i4 As Integer, i5 As Integer, i6 As Integer
  97. Dim PWord1 As String
  98. Dim ShTag As Boolean, WinTag As Boolean
  99.  
  100. Application.ScreenUpdating = False
  101. With ActiveWorkbook
  102. WinTag = .ProtectStructure Or .ProtectWindows
  103. End With
  104. ShTag = False
  105. For Each w1 In Worksheets
  106. ShTag = ShTag Or w1.ProtectContents
  107. Next w1
  108. If Not ShTag And Not WinTag Then
  109. 'MsgBox MSGNOPWORDS1, vbInformation, HEADER
  110. Exit Sub
  111. End If
  112. 'MsgBox MSGTAKETIME, vbInformation, HEADER
  113. If Not WinTag Then
  114. 'MsgBox MSGNOPWORDS2, vbInformation, HEADER
  115. Else
  116. On Error Resume Next
  117. Do 'dummy do loop
  118. For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
  119. For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
  120. For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
  121. For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
  122. With ActiveWorkbook
  123. .Unprotect Chr(i) & Chr(j) & Chr(k) & _
  124. Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
  125. Chr(i3) & Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
  126. If .ProtectStructure = False And _
  127. .ProtectWindows = False Then
  128. PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
  129. Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
  130. Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
  131. 'MsgBox Application.Substitute(MSGPWORDFOUND1, _
  132. "$$", PWord1), vbInformation, HEADER
  133. Exit Do 'Bypass all for...nexts
  134. End If
  135. End With
  136. Next: Next: Next: Next: Next: Next
  137. Next: Next: Next: Next: Next: Next
  138. Loop Until True
  139. On Error GoTo 0
  140. End If
  141. If WinTag And Not ShTag Then
  142. 'MsgBox MSGONLYONE, vbInformation, HEADER
  143. Exit Sub
  144. End If
  145. On Error Resume Next
  146. For Each w1 In Worksheets
  147. 'Attempt clearance with PWord1
  148. w1.Unprotect PWord1
  149. Next w1
  150. On Error GoTo 0
  151. ShTag = False
  152. For Each w1 In Worksheets
  153. 'Checks for all clear ShTag triggered to 1 if not.
  154. ShTag = ShTag Or w1.ProtectContents
  155. Next w1
  156. If ShTag Then
  157. For Each w1 In Worksheets
  158. With w1
  159. If .ProtectContents Then
  160. On Error Resume Next
  161. Do 'Dummy do loop
  162. For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
  163. For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
  164. For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
  165. For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
  166. .Unprotect Chr(i) & Chr(j) & Chr(k) & _
  167. Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
  168. Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
  169. If Not .ProtectContents Then
  170. PWord1 = Chr(i) & Chr(j) & Chr(k) & Chr(l) & _
  171. Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
  172. Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
  173. 'MsgBox Application.Substitute(MSGPWORDFOUND2, _
  174. "$$", PWord1), vbInformation, HEADER
  175. 'leverage finding Pword by trying on other sheets
  176. For Each w2 In Worksheets
  177. w2.Unprotect PWord1
  178. Next w2
  179. Exit Do 'Bypass all for...nexts
  180. End If
  181. Next: Next: Next: Next: Next: Next
  182. Next: Next: Next: Next: Next: Next
  183. Loop Until True
  184. On Error GoTo 0
  185. End If
  186. End With
  187. Next w1
  188. End If
  189. 'MsgBox ALLCLEAR & AUTHORS & VERSION & REPBACK, vbInformation, HEADER
  190.  
  191. 'Application.ScreenUpdating = True
  192. Application.DisplayAlerts = True
  193. End Sub
Add Comment
Please, Sign In to add comment