Deactivate Alt F11

Hi Bugs,

Try :

With Application
.OnKey "%{F11}", ""
End With

If you are trying to prevent people using the VBE you might also want to include this line to close the VBE if it is already open.

Application.VBE.MainWindow.Visible = False

HTH

EDIT: Typos!



_________________<font color="blue"> «««<font color="red">¤<font color="blue"><font size=+1>Richie</font><font color="red">¤<font color="blue"> »»»</font>

caffeine_sample.gif
</gif>
This message was edited by Richie(UK) on 2002-10-10 07:04
 
Upvote 0
I am second-guessing you here, in that I assume you want to keep others out of your project.

You can lock the project, and for added security, you can reduce all variable and routine names to two-character codes (that easily covers 700 variables), and remove all comments.

As for disabling the VBA Editor, others may know how. That detail has never captured my attention.
 
Upvote 0
Add to JP's reply...

<PRE><FONT color=red>Sub </FONT>DisableVBE()

<FONT color=red>Dim </FONT>myMenu <FONT color=red>As</FONT> CommandBar

<FONT color=red>Set </FONT>myMenu = Application.CommandBars("Worksheet Menu Bar")

myMenu.Controls(6).Controls(11).Controls(4).Enabled =<FONT color=red> False</FONT>

Application.OnKey "%{F11}", ""

<FONT color=red>End Sub</FONT>



<FONT color=red>Sub </FONT>EnableVBE()

<FONT color=red>Dim </FONT>myMenu <FONT color=red>As</FONT> CommandBar

<FONT color=red>Set </FONT>myMenu = Application.CommandBars("Worksheet Menu Bar")

myMenu.Controls(6).Controls(11).Controls(4).Enabled =<FONT color=red> True</FONT>

Application.OnKey "%{F11}"

<FONT color=red>End Sub</FONT>


</PRE>
 
Upvote 0
On 2002-10-10 06:47, Bugs wrote:
Is there a way of deactivating Alt F11

Bugs...do you ONLY want to disable the Alt F11 OR are you really tying to disable access to the VBA Editor?

If you need to disable Access then
1st Option Protect your project.

Other wise use this Routine.

<PRE><FONT color=blue>Option Explicit</FONT>



<FONT color=#008000>'// Tested Excel2000
</FONT>
<FONT color=#008000>'// Run DisableGettingIntoVBE from a Event procedure
</FONT>
<FONT color=#008000>'// eg. Workbook_Open or Worksheet_Activate
</FONT>
<FONT color=#008000>'// THEN run EnableGettingIntoVBE from the Opp Event procedure
</FONT>
<FONT color=#008000>'// eg. Workbook_Close or Worksheet_Deactivate
</FONT>
<FONT color=#008000>'//=====================================================================
</FONT>
<FONT color=#008000>'// Note:
</FONT>
<FONT color=#008000>'// In order to Disable access into the VBA Editor
</FONT>
<FONT color=#008000>'// you must Disable ALL references to Access the code
</FONT>
<FONT color=#008000>'// eg Macros...dialog,View Code - available via RighClick on Sheet Tab
</FONT>
<FONT color=#008000>'// Record New Macro..., and also Design Mode as the User can put the
</FONT>
<FONT color=#008000>'// workbook in design mode then select a control & double clcik to
</FONT>
<FONT color=#008000>'// view code. Alo you need to Disable the Custom Toolbar List AND
</FONT>
<FONT color=#008000>'// the fact that Double clicking ANY area of the commandbars will
</FONT>
<FONT color=#008000>'// also give you the Customize Toolbars Option Dialog.
</FONT>


<FONT color=#008000>'// The following Routine Takes care of this.
</FONT>
<FONT color=blue>Sub </FONT>DisableGettingIntoVBE()

Application.VBE.MainWindow.Visible =<FONT color=blue> False</FONT> <FONT color=#008000>'// Close ALL windows 1st!
</FONT>
CmdControl 1695,<FONT color=blue> False</FONT> <FONT color=#008000>'// Visual basics Editor
</FONT>
CmdControl 186,<FONT color=blue> False</FONT> <FONT color=#008000>'// Macros...
</FONT>
CmdControl 184,<FONT color=blue> False</FONT> <FONT color=#008000>'// Record New Macro...
</FONT>
CmdControl 1561,<FONT color=blue> False</FONT> <FONT color=#008000>'// View Code
</FONT>
CmdControl 1605,<FONT color=blue> False</FONT> <FONT color=#008000>'// Design Mode
</FONT>
Application.OnDoubleClick = "Dummy"

CommandBars("ToolBar List").Enabled =<FONT color=blue> False</FONT>

Application.OnKey "%{F11}", "Dummy"

<FONT color=blue>End Sub</FONT>



<FONT color=blue>Sub </FONT>EnableGettingIntoVBE()

CmdControl 1695,<FONT color=blue> True</FONT> <FONT color=#008000>'// Visual basics Editor
</FONT>
CmdControl 186,<FONT color=blue> True</FONT> <FONT color=#008000>'// Macros...
</FONT>
CmdControl 184,<FONT color=blue> True</FONT> <FONT color=#008000>'// Record New Macro...
</FONT>
CmdControl 1561,<FONT color=blue> True</FONT> <FONT color=#008000>'// View Code
</FONT>
CmdControl 1605,<FONT color=blue> True</FONT> <FONT color=#008000>'// Design Mode
</FONT>
Application.OnDoubleClick = ""

CommandBars("ToolBar List").Enabled =<FONT color=blue> True</FONT>

Application.OnKey "%{F11}", ""

<FONT color=blue>End Sub</FONT>



<FONT color=blue>Sub </FONT>CmdControl(Id <FONT color=blue>As</FONT><FONT color=blue> Integer</FONT>, TF <FONT color=blue>As</FONT> <FONT color=blue>Boolean</FONT>)

<FONT color=blue>Dim </FONT>CBar <FONT color=blue>As</FONT> CommandBar

<FONT color=blue>Dim </FONT>C <FONT color=blue>As</FONT> CommandBarControl



<FONT color=blue>On Error</FONT> <FONT color=blue>Resume </FONT><FONT color=blue>Next</FONT>

<FONT color=blue>For </FONT>Each CBar In Application.CommandBars

<FONT color=blue>Set </FONT>C = CBar.FindControl(Id:=Id, recursive:=True)

<FONT color=blue>If </FONT>Not C Is<FONT color=blue> Nothing</FONT><FONT color=blue> Then </FONT>C.Enabled = TF

<FONT color=blue>Next</FONT>



<FONT color=blue>End Sub</FONT>



<FONT color=blue>Sub </FONT>Dummy()

<FONT color=#008000> '// NoGo, leave blank OR Display a message eg.
</FONT>
<FONT color=#008000> 'MsgBox "Sorry you this command is NOT available", vbCritical
</FONT>
<FONT color=blue>End Sub</FONT>


</PRE>
 
Upvote 0
As I want to prevent access to my VBA project I am trying to use this code in VBA Excel 2010 and I don't see any change except in status of properties. But still I can access all command bars.

Could you please help me out I am not sure what I am doing wrong?

Many thanks!

Bugs...do you ONLY want to disable the Alt F11 OR are you really tying to disable access to the VBA Editor?

If you need to disable Access then
1st Option Protect your project.

Other wise use this Routine.

Option Explicit







'// Tested Excel2000



'// Run DisableGettingIntoVBE from a Event procedure



'// eg. Workbook_Open or Worksheet_Activate



'// THEN run EnableGettingIntoVBE from the Opp Event procedure



'// eg. Workbook_Close or Worksheet_Deactivate



'//=====================================================================



'// Note:



'// In order to Disable access into the VBA Editor



'// you must Disable ALL references to Access the code



'// eg Macros...dialog,View Code - available via RighClick on Sheet Tab



'// Record New Macro..., and also Design Mode as the User can put the



'// workbook in design mode then select a control & double clcik to



'// view code. Alo you need to Disable the Custom Toolbar List AND



'// the fact that Double clicking ANY area of the commandbars will



'// also give you the Customize Toolbars Option Dialog.







'// The following Routine Takes care of this.



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







Sub EnableGettingIntoVBE()



CmdControl 1695, True '// Visual basics Editor



CmdControl 186, True '// Macros...



CmdControl 184, True '// Record New Macro...



CmdControl 1561, True '// View Code



CmdControl 1605, True '// Design Mode



Application.OnDoubleClick = ""



CommandBars("ToolBar List").Enabled = True



Application.OnKey "%{F11}", ""



End Sub







Sub CmdControl(Id As Integer, TF As Boolean)



Dim CBar As CommandBar



Dim C As CommandBarControl







On Error Resume Next



For Each CBar In Application.CommandBars



Set C = CBar.FindControl(Id:=Id, recursive:=True)



If Not C Is Nothing Then C.Enabled = TF



Next







End Sub







Sub Dummy()



'// NoGo, leave blank OR Display a message eg.



'MsgBox "Sorry you this command is NOT available", vbCritical



End Sub
 
Upvote 0

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