I'm trying to save a file with a new password, but when I reopen the file still asks me for the old password. The code I have is as follows:
FileCopy strLastMonthFilePath, strFilePath
' Open MF
Workbooks.Open Filename:=strFilePath, Password:=OldPassword, UpdateLinks:=0
MF_FileName = ActiveWorkbook.Name
Application.DisplayAlerts = False
ThisWorkbook.SaveAs Password:=NewPassword
Application.DisplayAlerts = True
' Close Source files
Application.DisplayAlerts = False
Windows(MF_FileName).Activate
Workbooks(MF_FileName).Close
' This line does not work. If if change it to the OldPassword then it works
Workbooks.Open Filename:=strFilePath, Password:=NewPassword, UpdateLinks:=0
I tried also to assign the workbook and change the password to a variable but didn't work:
Set myWBk = Workbooks.Open(Filename:=strFilePath, Password:=OldPassword , UpdateLinks:=0)
myWBk.SaveAs Password:=NewPassword
Any idea why the password does not change?
ThisWorkbook- that's the workbook where the code is stored, not the workbook that you just opened.