Automatically Protect Workbook with Password

How to protect a workbook with encrypted password automatically using VBA. Here’s the complete VBA code:
Sub protectmyworkbook()
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=”C:\exceltrainingvideos\protectworkbookusingvba.xlsm”, FileFormat:=52, Password:=”TPio&2019″, writerespassword:=”TPio&2020″
Application.DisplayAlerts = True
End Sub

Private Sub Workbook_Open()
protectmyworkbook
End Sub

Watch the video below: