Forum Discussion

Toraji3's avatar
Toraji3
Copper Contributor
May 14, 2021
Solved

Recording a password by macro

Hi there, I wonder how to protect a workbook with a password leveraging macro. I am looking for a method to utilize Record Macro to make it happen without using codes in VBA. I’ve tried sever...
  • JMB17's avatar
    May 15, 2021

    Toraji3 

     

    No, the macro recorder does not record the password for the sake of security. If you look at the vba code the recorder creates, it  should look something like this:

     

     

    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
        ActiveWorkbook.Protect Structure:=True, Windows:=False
    End Sub

     

     

    But, you can edit the macro to include the password:

     

     

    Sub Macro1()
        
        ActiveWorkbook.Protect Structure:=True, Windows:=False, Password:="ABC123"
    
    End Sub

     

     

Resources