Prevent code on a worksheet from being revealed

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,924
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
We can protect VBA code by adding a password but there are third party software that can break that.

I have discovered also if a workbook contains code on the worksheets, even if it's password protected. it can be revealed without too much effort.

Is there any way to prevent this?

Thanks
 
Last edited by a moderator:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
There are a few things you can do to make it difficult; however, if someone wants in...they're gonna get in.
Here is a list of things I occasionally do.
- Use password to open. This will stop some of the common methods of breaking in.
- Use a workbook_beforesave function to only allow specific users to save. For example:
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If Environ("username") = "jrieger" Then
       Cancel = False
    Else
        Cancel = True
    End If

End Sub
- You could also add a workbook_open script to validate if the file extension is .xlsm and if not, close immediately.
- I have even gone so far as to add veryhidden sheets with fun names like "for admins only" to my workbooks with an on_activate script that deletes the entire file if someone opens the sheet...but not before it sends me an email with the offending user's address and login ID. Often people with prying eyes like to check things out...so you will be able to use this to identify who may be digging in.
 
Upvote 0
The fact of the matter is this: Excel is not a very secure program, and if anybody is motivated enough, they can usually "break" it with a little effort.

Excel is not known for their security. So if this kind of security is of utmost importance to you, then you may need to investigate choosing another program.
I find at best, Excel security is best to prevent users from accidentally stumbling upon something they shouldn't see or do. Users with an intent to break or hack can usually figure it out.
 
Upvote 0
There are a few things you can do to make it difficult; however, if someone wants in...they're gonna get in.
Here is a list of things I occasionally do.
- Use password to open. This will stop some of the common methods of breaking in.
- Use a workbook_beforesave function to only allow specific users to save. For example:
VBA Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If Environ("username") = "jrieger" Then
       Cancel = False
    Else
        Cancel = True
    End If

End Sub
- You could also add a workbook_open script to validate if the file extension is .xlsm and if not, close immediately.
- I have even gone so far as to add veryhidden sheets with fun names like "for admins only" to my workbooks with an on_activate script that deletes the entire file if someone opens the sheet...but not before it sends me an email with the offending user's address and login ID. Often people with prying eyes like to check things out...so you will be able to use this to identify who may be digging in.
Thanks, great suggestions.

The "most robust" method I've come across is the VBA was compiled using a DLL. That's close to 100% safe (but as you said, everything's breakabke).
 
Upvote 0
The fact of the matter is this: Excel is not a very secure program, and if anybody is motivated enough, they can usually "break" it with a little effort.

Excel is not known for their security. So if this kind of security is of utmost importance to you, then you may need to investigate choosing another program.
I find at best, Excel security is best to prevent users from accidentally stumbling upon something they shouldn't see or do. Users with an intent to break or hack can usually figure it out.
Yes, I agree Excel is quite flimsy but I was surprised one could retrieve the code of the worksheet so easily, literally with no hacking.
 
Upvote 0

Forum statistics

Threads
1,224,163
Messages
6,176,814
Members
452,744
Latest member
Alleo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top