Jeg har i gamle dage brugt denne formel, men virker ikke mere på win 11 og nyeste excel
Sub PasswordBreaker() 'Knækker arkbeskyttelse. 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 "Koden er brudt og dokumenet kan nu rettes!", vbExclamation + vbOKOnly Exit Sub End If Next Next Next Next Next Next Next Next Next Next Next Next End Sub
#6 - Dette er ikke en metode man skal rode sig ud i, hvis ikke man har fuld styr på brugen af Hex editor. Desuden så virker det ikke på Excel filer som er baseret på f.eks. Excel 365.
Jeg fandt denne for noget tid siden. Den virker upåklageligt: Sub RemoveProtection()
Dim dialogBox As FileDialog Dim sourceFullName As String Dim sourceFilePath As String Dim sourceFileName As String Dim sourceFileType As String Dim newFileName As Variant Dim tempFileName As String Dim zipFilePath As Variant Dim oApp As Object Dim FSO As Object Dim xmlSheetFile As String Dim xmlFile As Integer Dim xmlFileContent As String Dim xmlStartProtectionCode As Double Dim xmlEndProtectionCode As Double Dim xmlProtectionString As String
'Open dialog box to select a file Set dialogBox = Application.FileDialog(msoFileDialogFilePicker) dialogBox.AllowMultiSelect = False dialogBox.Title = "Select file to remove protection from"
If dialogBox.Show = -1 Then sourceFullName = dialogBox.SelectedItems(1) Else Exit Sub End If
'Get folder path, file type and file name from the sourceFullName sourceFilePath = Left(sourceFullName, InStrRev(sourceFullName, "\")) sourceFileType = Mid(sourceFullName, InStrRev(sourceFullName, ".") + 1) sourceFileName = Mid(sourceFullName, Len(sourceFilePath) + 1) sourceFileName = Left(sourceFileName, InStrRev(sourceFileName, ".") - 1)
'Use the date and time to create a unique file name tempFileName = "Temp" & Format(Now, " dd-mmm-yy h-mm-ss")
'Copy and rename original file to a zip file with a unique name newFileName = sourceFilePath & tempFileName & ".zip" On Error Resume Next FileCopy sourceFullName, newFileName
If Err.Number <> 0 Then MsgBox "Unable to copy " & sourceFullName & vbNewLine _ & "Check the file is closed and try again" Exit Sub End If On Error GoTo 0
'Create folder to unzip to zipFilePath = sourceFilePath & tempFileName & "\" MkDir zipFilePath
'Extract the files into the newly created folder Set oApp = CreateObject("Shell.Application") oApp.Namespace(zipFilePath).CopyHere oApp.Namespace(newFileName).items
'loop through each file in the \xl\worksheets folder of the unzipped file xmlSheetFile = Dir(zipFilePath & "\xl\worksheets\*.xml*") Do While xmlSheetFile <> ""
'Read text of the file to a variable xmlFile = FreeFile Open zipFilePath & "xl\worksheets\" & xmlSheetFile For Input As xmlFile xmlFileContent = Input(LOF(xmlFile), xmlFile) Close xmlFile
'Manipulate the text in the file xmlStartProtectionCode = 0 xmlStartProtectionCode = InStr(1, xmlFileContent, "<sheetProtection")
'Output the text of the variable to the file xmlFile = FreeFile Open zipFilePath & "xl\worksheets\" & xmlSheetFile For Output As xmlFile Print #xmlFile, xmlFileContent Close xmlFile
'Loop to next xmlFile in directory xmlSheetFile = Dir
Loop
'Read text of the xl\workbook.xml file to a variable xmlFile = FreeFile Open zipFilePath & "xl\workbook.xml" For Input As xmlFile xmlFileContent = Input(LOF(xmlFile), xmlFile) Close xmlFile
'Manipulate the text in the file to remove the workbook protection xmlStartProtectionCode = 0 xmlStartProtectionCode = InStr(1, xmlFileContent, "<workbookProtection") If xmlStartProtectionCode > 0 Then
'Manipulate the text in the file to remove the modify password xmlStartProtectionCode = 0 xmlStartProtectionCode = InStr(1, xmlFileContent, "<fileSharing") If xmlStartProtectionCode > 0 Then
'Output the text of the variable to the file xmlFile = FreeFile Open zipFilePath & "xl\workbook.xml" & xmlSheetFile For Output As xmlFile Print #xmlFile, xmlFileContent Close xmlFile
'Create empty Zip File Open sourceFilePath & tempFileName & ".zip" For Output As #1 Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0) Close #1
'Move files into the zip file oApp.Namespace(sourceFilePath & tempFileName & ".zip").CopyHere _ oApp.Namespace(zipFilePath).items 'Keep script waiting until Compressing is done On Error Resume Next Do Until oApp.Namespace(sourceFilePath & tempFileName & ".zip").items.Count = _ oApp.Namespace(zipFilePath).items.Count Application.Wait (Now + TimeValue("0:00:01")) Loop On Error GoTo 0
'Delete the files & folders created during the sub Set FSO = CreateObject("scripting.filesystemobject") FSO.deletefolder sourceFilePath & tempFileName
'Rename the final file back to an xlsx file Name sourceFilePath & tempFileName & ".zip" As sourceFilePath & sourceFileName _ & "_" & Format(Now, "dd-mmm-yy h-mm-ss") & "." & sourceFileType
'Show message box MsgBox "The workbook and worksheet protection passwords have been removed.", _ vbInformation + vbOKOnly, Title:="Password protection"
Tak for jeres input, lukker tråden, fik det ikke til at virke
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.