reubenjacobc
New Member
- Joined
- May 26, 2023
- Messages
- 2
- Office Version
- 2019
Hi Everyone,
I am working to password protect all the excel files in a folder based on the file path and password entered in an excel sheet. After I run the code, the files in the folder are encrypted, but they are all blank and all the previous contents have been cleared.
Can anyone tell me what I am doing wrong?? Below is the code:
Set wslist = ThisWorkbook.Worksheets("Home_Page")
With wslist
For i = first_row To last_row - 1
'Worksheets("Processing File").Cells(i, 4) = Worksheets("Home_Page").Cells(i, 5).Value
file_name = Worksheets("Home_Page").Cells(i, 5).Value
temp_password = Worksheets("Home_Page").Cells(i, 6).Value
'ActiveWorkbook.SaveCopyAs filename:=file_name, FileFormat:=xlOpenXMLWorkbook
Set masterWB = Workbooks.Add
masterWB.SaveAs filename:=file_name, FileFormat:=xlOpenXMLWorkbook, password:=temp_password
masterWB.Close
Set WB = Nothing
Next i
End With
Thank you so much for your help!
PS: I am pretty new to VBA
I am working to password protect all the excel files in a folder based on the file path and password entered in an excel sheet. After I run the code, the files in the folder are encrypted, but they are all blank and all the previous contents have been cleared.
Can anyone tell me what I am doing wrong?? Below is the code:
Set wslist = ThisWorkbook.Worksheets("Home_Page")
With wslist
For i = first_row To last_row - 1
'Worksheets("Processing File").Cells(i, 4) = Worksheets("Home_Page").Cells(i, 5).Value
file_name = Worksheets("Home_Page").Cells(i, 5).Value
temp_password = Worksheets("Home_Page").Cells(i, 6).Value
'ActiveWorkbook.SaveCopyAs filename:=file_name, FileFormat:=xlOpenXMLWorkbook
Set masterWB = Workbooks.Add
masterWB.SaveAs filename:=file_name, FileFormat:=xlOpenXMLWorkbook, password:=temp_password
masterWB.Close
Set WB = Nothing
Next i
End With
Thank you so much for your help!
PS: I am pretty new to VBA