unknownymous
Board Regular
- Joined
- Sep 19, 2017
- Messages
- 249
- Office Version
- 2016
- Platform
- Windows
Hi Guys,
Can you possibly help me tweak this code? I'm thinking in Sheet1, I'll put the pathfile link in Cell F1 then Password in Cell F2. Also, how to avoid getting error when the file is in read-only format.
= = = = = =
Sub PasswordRemover()
Dim wBook As Workbook
Dim strFilename As String
'Const fPath As String = "C:\Users\Documents\"
Const strPassword As String = "12345ABC&D" 'case sensitive
Const strEditPassword As String = "12345ABC&D" 'If no password use ""
strFilename = Dir$(fPath & "*.xls") 'will open xls & xlsx etc
While Len(strFilename) <> 0
Application.DisplayAlerts = False
Set wBook = Workbooks.Open(Filename:=fPath & strFilename, _
Password:=strPassword, _
WriteResPassword:=strEditPassword)
'ActiveWorkbook.ChangeFileAccess Mode:=xlReadWrite
wBook.SaveAs Filename:=fPath & strFilename, CreateBackup:=False, WriteResPassword:="", Password:="" ', ReadOnlyRecommended:=False
wBook.Close 0
Application.DisplayAlerts = True
strFilename = Dir$()
Wend
End Sub
Any thoughts will be much appreciated.
Thank you!
Can you possibly help me tweak this code? I'm thinking in Sheet1, I'll put the pathfile link in Cell F1 then Password in Cell F2. Also, how to avoid getting error when the file is in read-only format.
= = = = = =
Sub PasswordRemover()
Dim wBook As Workbook
Dim strFilename As String
'Const fPath As String = "C:\Users\Documents\"
Const strPassword As String = "12345ABC&D" 'case sensitive
Const strEditPassword As String = "12345ABC&D" 'If no password use ""
strFilename = Dir$(fPath & "*.xls") 'will open xls & xlsx etc
While Len(strFilename) <> 0
Application.DisplayAlerts = False
Set wBook = Workbooks.Open(Filename:=fPath & strFilename, _
Password:=strPassword, _
WriteResPassword:=strEditPassword)
'ActiveWorkbook.ChangeFileAccess Mode:=xlReadWrite
wBook.SaveAs Filename:=fPath & strFilename, CreateBackup:=False, WriteResPassword:="", Password:="" ', ReadOnlyRecommended:=False
wBook.Close 0
Application.DisplayAlerts = True
strFilename = Dir$()
Wend
End Sub
Any thoughts will be much appreciated.
Thank you!