I have the following code which saves each worksheet in a workbook as separate files with a password. However each file has the same password and I need them to have a different password. How can I achieve this? A separate sheet to store the passwords on would be OK but I then need to know how to reference the words in the loop. Better still would be to have the passwords in the VBA. Thanks.
Sub saveworksheets()
Dim ws As Worksheet
Dim wb As Workbook
For Each ws In ThisWorkbook.Worksheets
Set wb = Workbooks.Add
wb.SaveAs ThisWorkbook.Path & "\" & ws.Name & ".xlsx", Password:="12345"
ws.Copy before:=wb.Worksheets(1)
wb.Close savechanges:=True
Next ws
'
' Keyboard Shortcut: Ctrl+x
'
End Sub
Sub saveworksheets()
Dim ws As Worksheet
Dim wb As Workbook
For Each ws In ThisWorkbook.Worksheets
Set wb = Workbooks.Add
wb.SaveAs ThisWorkbook.Path & "\" & ws.Name & ".xlsx", Password:="12345"
ws.Copy before:=wb.Worksheets(1)
wb.Close savechanges:=True
Next ws
'
' Keyboard Shortcut: Ctrl+x
'
End Sub