Disable code viewing

jkeyes

Active Member
Joined
Apr 15, 2003
Messages
343
I searched and found Ivan's code for disabling all methods of viewing code here:

Code:
Sub DisableGettingIntoVBE()
   Application.VBE.MainWindow.Visible = False '// Close ALL windows 1st!
   CmdControl 1695, False                     '// Visual basics Editor
   CmdControl 186, False                      '// Macros...
   CmdControl 184, False                      '// Record New Macro...
   CmdControl 1561, False                     '// View Code
   CmdControl 1605, False                     '// Design Mode
   Application.OnDoubleClick = "Dummy"
   CommandBars("ToolBar List").Enabled = False
   Application.OnKey "%{F11}", "Dummy"
End Sub

The first line in the sub, however, is giving me a runtime error '1004', Programmatic access to VB project is not trusted.

Other than that line, everything works great... any ideas on a fix?

Thanks!
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Why not just protect the VBE with a password instead of all this ?
1. Go into VBE
2. Select tools on menu
3. Select VBA Projects properties
4. In Properties window set password on Protection tab
 
Upvote 0
jkeyes said:
I searched and found Ivan's code for disabling all methods of viewing code here:

Code:
Sub DisableGettingIntoVBE()
   Application.VBE.MainWindow.Visible = False '// Close ALL windows 1st!
   CmdControl 1695, False                     '// Visual basics Editor
   CmdControl 186, False                      '// Macros...
   CmdControl 184, False                      '// Record New Macro...
   CmdControl 1561, False                     '// View Code
   CmdControl 1605, False                     '// Design Mode
   Application.OnDoubleClick = "Dummy"
   CommandBars("ToolBar List").Enabled = False
   Application.OnKey "%{F11}", "Dummy"
End Sub

The first line in the sub, however, is giving me a runtime error '1004', Programmatic access to VB project is not trusted.

Other than that line, everything works great... any ideas on a fix?

Thanks!

To fix your problem click Tools, Macros, Security and then click on the Trusted Sources tab. Tick the 'Trust access to Visual Basic project' checkbox and then click OK. However, Nimrod's solution is far more effective if you want to stop someone viewing your code :)
 
Upvote 0
Putting a password on code is only minimally useful without also preventing access to VBA. Users with access to VBA can run code in the immediate window, and most especially, can turn off event handling.
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,040
Members
449,063
Latest member
ak94

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