View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default how to open and remove passwords in bulk

Gordon, the code below will allow you to browse and choose any number of
files and once you've completed that part (by clicking [Cancel] in the file
open dialog), it will begin opening those files using the password set in the
code and then saving them back to their original location without a password.
They will have the same name.

Without more specifics, I can't get much more 'efficient'. If all of the
workbooks were in a single folder, the 'get filenames list' part of the code
could do it without you having to choose them one by one, but I'm assuming
they're scattered about in various folders.

To put the code into use: create a new workbook and then open the VB Editor
using [Alt]+[F11]. Choose Insert | Module from the VBE menu toolbar. Copy
and paste this code into the module, change the Const masterPassword to
contain the proper password, then you can either press [F5] to run it right
there, or close the VB Editor and use Tools | Macro | Macros to run the code.
Your screen will remain unchanging while the process takes place, and a
message will appear when it has all been accomplished.

Sub OpenAndRemovePasswords()
Const masterPassword = "myPassword"
Dim filesList() As String
Dim anyFilename As Variant
Dim lCount As Integer

ReDim filesList(1 To 1) ' initialize

'get list of files to process
'will loop until [Cancel] is used
anyFilename = "kickstart" ' just to initialize the loop
Do While anyFilename < ""
anyFilename = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
If anyFilename < False Then
If filesList(UBound(filesList)) < "" Then
ReDim Preserve filesList(1 To UBound(filesList) + 1)
End If
filesList(UBound(filesList)) = anyFilename
Else ' was false, no file chosen
anyFilename = ""
End If
Loop
Application.ScreenUpdating = False
For lCount = LBound(filesList) To UBound(filesList)
If filesList(lCount) < "" Then
Workbooks.Open Filename:=filesList(lCount), _
Password:=masterPassword
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=filesList(lCount), _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWorkbook.Close
Application.DisplayAlerts = True
End If
Next
Application.ScreenUpdating = True
MsgBox "All files have had their password removed"
End Sub


"gordon" wrote:

Hi

My work has about 500 excel files with the same password to edit the files.
I have the password and I need to open each file and save it without the
password so another application can read them. The other application can
read only excel that doesnt have passwords.

Does anyone know an efficient way to do this?

Doug