Hide worksheet in Excel Add-In from other VBA Proj

2019-08-17 19:11发布

I have an Excel Add-In which I am building which stores users settings in a Settings worksheet within the Add-In. I use the Settings sheet essentially as storage for boolean values and potentially, the user's registration details.

However, if I open up a new VBA Project and include the Add-In as a reference (In VBA: Tools > References > MY Add-In) then I can access the Settings worksheet and potentially break the password on it and hack the registration details.

The Settings sheet is set to be xlVeryHidden however it can be accessed via VBA code. Is there anyway to prevent this in Excel? In a module for example I can use the Option Private Module method.

1条回答
劫难
2楼-- · 2019-08-17 20:01

If you password protect and lock the project then your code and the worksheet objects can't be viewed. Go to Tools > VBAObject properties > Protection tab then tick 'Lock Project For Viewing' and then set a password in 'Password to view object properties'.

However, there is nothing to stop a hacker from...

For s = 1 to Sheets.Count
   Sheets(s).visible = True
Next s

...to see your Settings sheet.

There are a few options:

1) Have the settings sheet in a seperate workbook, or some other format like .txt and read from that (recommended).

2) Use some kind of encryption in your Setting sheet and decrypt it in your code, a really simple example is to use numbers in place of text so 'example' would = '5,24,1,13,16,12,5', but obviously you want to employ something more sophisticated that than and you can search online for many ways to do it.

3) Use 2, but store the decryption code somewhere else.

Be aware though, that for someone who knows what they're doing there really is no way to prevent a VBA hack, unless you use option 1/3 and have a way to store the file somewhere that isn't publicly accessible.

查看更多
登录 后发表回答