Wednesday 29 March 2023

Macro to unprotect multiple workbooks in a Folder

Object of the Macro:


Multiple excel workbooks are in a folder.

Each workbook is protected by a password.

I want to get them unprotected using a the password and get them pooled into a folder.


Code:

 

 

Sub Hell3()

    Dim WB As Workbook

    Dim xFd As FileDialog

    Dim xFdItem As Variant

    Dim xFileName As String

    Set xFd = Application.FileDialog(msoFileDialogFolderPicker)

 

    If xFd.Show = -1 Then

        xFdItem = xFd.SelectedItems(1) & Application.PathSeparator

        xFileName = Dir(xFdItem & "*.xls*")

        MkDir xFdItem & "\Password Removed Files"

        Do While xFileName <> ""

            Set WB = Workbooks.Open((xFdItem & xFileName), Password:="pass")

 

                WB.SaveAs Filename:=xFdItem & "Password Removed Files\" & xFileName, FileFormat:=51, Password:="", WriteResPassword:="", _

                ReadOnlyRecommended:=False, CreateBackup:=False

 

                WB.Close True

             xFileName = Dir

        Loop

    End If

 End Sub


Note: 


Ensure to replace the word "pass" with your actual password in the code