Protecting VB Editor

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,924
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
It is possible to prevent users from seeing the VBA by adding a password (admittedly though it can be easily cracked).

However, is it possible to prevent users from opening the VB Editor at all?

The reason is my program has events but supposing for argument sake, the user opens the VB Editor and types in the Immediate Window (which they have access to, even if the code is password protected):

Code:
Application.EnableEvents = False

then my program will not behave as expected.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Locking the VBProject from view will not prevent a stubborn user from disabling the application events from the Immediate Window or from code from another VBProject .. etc .

One thing I did in a project of mine was to have code to periodically check the Application Events status and automatically reset it to True if disabled.

Place this in the ThisWorkbook Module :

Code:
Private WithEvents cmbrs As CommandBars

Private Sub Workbook_Open()
    Set cmbrs = Application.CommandBars
End Sub


Private Sub cmbrs_OnUpdate()
    If Not Application.EnableEvents Then Application.EnableEvents = True
End Sub

The above code will ensure that the Application Events are enabled throughout the life of the workbook.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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