To save the files as protected files and display a message when someone tries to make changes without the appropriate password, you can use the following adjusted code:
Code:
For r = FirstRow To sws.Cells(sws.Rows.Count, "A").End(xlUp).Row
sws.Rows(r).Copy dfCell
dName = CStr(sws.Cells(r, "A").Value) & NAME_DELIMITER _
& CStr(sws.Cells(r, "B").Value)
If Len(dName) > ndLen Then
dws.Name = dName
dFilePath = dFolderPath & dName & ".xlsx"
Application.DisplayAlerts = False
dwb.SaveAs dFilePath, xlOpenXMLWorkbook
Application.DisplayAlerts = True
' Protect the workbook
Dim wb As Workbook
Set wb = Workbooks.Open(dFilePath)
wb.Protect Password:="YourPassword", Structure:=True, Windows:=False
' Add a message to prevent unauthorized changes
wb.ShowPivotTableFieldList = False ' This line is optional, it hides the PivotTable Field List
wb.CustomViews.Add ViewName:="ProtectedView"
MsgBox "Changes cannot be made without the appropriate password.", vbInformation, "Protected File"
dCount = dCount + 1
End If
Next r
Replace "YourPassword" with the appropriate password you want to use to protect the files. This code will protect the saved files with the specified password and display a message if someone tries to make changes without the appropriate password.
Bookmarks