Unprotect sheet with password, without exposing password in the macro

前端 未结 3 1514
逝去的感伤
逝去的感伤 2021-02-20 17:33

I have recently started writing some Macro\'s in Excel. I have a protected worksheet, and a few buttons that allow the user to add/remove columns/rows at a certain point in the

3条回答
  •  耶瑟儿~
    2021-02-20 18:07

    Two options:

    1. Password protect the VBA. (While VBA protection is far from secure against malicious intent, it is no worse than the security of sheet protection)
    2. If you set the worksheet protection using VBA you can specify UserInterfaceOnly:=True.

      sh.Protect Password:="Password", UserInterfaceOnly:=True

      Once set in this way VBA code can modify the sheet without supplying a password. Since the password must be supplied once to apply protection in the first place, run this code from a seperate workbook or addin you keep to yourself.

提交回复
热议问题