VBA password protect Excel workbook

VBA to password protect a workbook. Can be used to automatically protect multiple workbooks by looping through all the workbooks and password protecting them.

Update xlFileSaveName = “Z:\test.xls”   with the filepath to your workbook
Update CurrMgrPwrd = “TestPW” with your password


Dim xlFileSaveName As String
Dim wkb As Excel.Workbook
xlFileSaveName = “Z:\test.xls"
Set wkb = xlApp.Workbooks.Open(xlFileSaveName)
CurrMgrPwrd = “TestPW”
wkb.Password = CurrMgrPwrd
[efb_likebox fanpage_url="https://www.facebook.com/vbamarket/" box_width="840" box_height=340"" responsive="1" show_faces="1" show_stream="1" hide_cover="1" small_header="0" hide_cta="0" locale="en_US"]