Forum Discussion
Toraji3
May 14, 2021Copper Contributor
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...
- May 15, 2021
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
JMB17
May 15, 2021Bronze Contributor
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
Toraji3
May 17, 2021Copper Contributor
Thank you for your response very much. The information you provided helps me to understand Excel macro more deeply.