Home > Software engineering >  Batch remove password Excel VBA code? To solve problems is pointed out that code, modify the code
Batch remove password Excel VBA code? To solve problems is pointed out that code, modify the code

Time:09-16

I to solve the question now is: I have a lot of excel files in the same folder, file has the same password and I know, I want to remove all the password, make each excel file directly to open the file, the sheet is in the excel file without password, I see a code in baidu knows, is to decrypt the excel files in the local folders, but I according to its operation without success, hope to have a master to help me take a look at how to modify the can realize my demand, thank!!!!!!

Reference: https://zhidao.baidu.com/question/2117910715489312707.html
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Xx (Sub)
Dim PTH, fn, I, j, n
PTH=ThisWorkbook. Path & amp; ""
Fn=Dir (PTH & amp; "*. XLS")
The Do While fn & lt;> "
"If fn & lt;> ThisWorkbook. Name Then
Application. The Workbooks. Open PTH & amp; Fn
N=Workbooks (fn). Sheets. Count
For j=1 To n
Workbooks (fn) Sheets (j) Unprotect "TZHJTDWIVSBWYKU
"Next
Application. Workbooks (fn). Close True
End the If
Fn=Dir
Loop
End Sub
Create a new excel file, Alt + F11 opened the VBE varies, create a new module, copy the code above, exit the VBE varies, keep the excel file to decrypt the folder, performs macro xx
_______________________________________________________________________________________________________________________

CodePudding user response:

Recording a macro, and then change, iterate over all the files

CodePudding user response:

reference 1/f, crispy big ice cream reply:
to record a macro, then change, just iterate over all files


Remove the password, is excel at first thing, so I don't know the recording to decrypt the front there are useless, then there is something wrong with the code above, please?

CodePudding user response:

First of all, your code is to Unprotect sheet, rather than to Unprotect Workbook, concrete should be Workbook. Unprotect method,
Second, Workbook. Unprotect delete table or the protection of the Workbook, open this Workbook, you want to enter the password to Unprotect

Application. The Workbooks. Open PTH & amp; Fn, Password:="TZHJTDWIVSBWYKU"

CodePudding user response:

Xx (Sub)
Dim PTH, fn, I, j, n
PTH=ThisWorkbook. Path & amp; ""
Fn=Dir (PTH & amp; "*. XLS")
The Do While fn & lt;> "
"If fn & lt;> ThisWorkbook. Name Then
Application. The Workbooks. Open PTH & amp; Fn,,,, "password" work thin
Workbooks (fn). Unprotect "password" work thin
Application. Workbooks (fn). Close True
End the If
Fn=Dir
Loop
End Sub
  •  Tags:  
  • VBA
  • Related