September 20, 2019

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:

One thought on “Automatically Protect Workbook with Password

  1. Dear Sir,
    is it possible to write a macro to password protect the workbook NOT save or modify from the original version? for example, excel workbook with function and macro people can use the workbook but not save or modify from the original version

Comments are closed.