Search code examples
vbaexcelvbe

VBA Security : my vbe password is well-set, but still can be hacked by a simple code


I have a xlsm workbook and with 2 sheets, I call it as workbook 1, sheet 1 is visible, sheet 2 is set as xlsheetveryhidden. And then vbe password setted.

Now the situation should be no one can unhide sheet 2 manaually, right?

Now I open another workbook, I call it as workbook 2, open vbe at workbook 2, and simply type the following codes and aim to workbook 1, sheet 2 is visble:

Sub InvisibleSheet2Fails()
Sheets(2).Visible = xlSheetVisible
End Sub
 

My question is: How can I unhide my sheet 2 ONLY with workbook 1 vbe password? workbook 2 doesn't know the workbook 1 vbe password but can easily bypass xlsheetveryhidden setting.

Thank you very much!

Lawrence


Solution

  • No security is 100% safe. If your threat model is a power user that knows how to bring up the VBE and you don't want them fiddling around, you can at least protect the workbook structure with a password.

    ThisWorkbook.Protect "password", Structure:=true
    

    Do this from the immediate pane, don't put the password anywhere in the code - VBE password protection on the other hand (you seem to be conflating VBA project protection and workbook structure protection), is absolutely easily defeated, in no time; if you've written the password anywhere in the code, consider it compromised.

    Use a good, strong password, and if you're using the latest version of Excel and someone manages to unprotect the workbook, they deserve to tweak it.

    If your threat model is a MI6 agent, if they get to the file in the first place, you already lost: put the file somewhere safe, implement good network security.