Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Howard Dixon   on Nov 20 In MS Office Category.

  
Question Answered By: Alfie Evans   on Nov 20

If you want to prevent  the user from going into VBA Debugger on an error, you
can also password  the VBA Project code  by right-clicking on "Microsoft Excel
Objects"
while you are in the VBA Editor. A panel will appear, then select the
"Protection" tab
and select the "Lock project for viewing" and also put  in a password for the
whole project.
Also, here is some VBA code to prevent a user getting(hacking) into VBA code.
--------------------------------------------------------------------------------\
-------------------------
Option Explicit
'//=====================================================================
'// Run DisV from Workbook_Open or Worksheet_Activate
'// THEN run EnaV from 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..., Design Mode as the User can put the
'// workbook in design mode then select a control & double click to
'// view code, right click top Document area  etc
'// Also 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.
Const dCustomize As Double = 797
Const dVbEditor As Double = 1695
Const dMacros As Double = 186
Const dRecordNewMacro As Double = 184
Const dViewCode As Double = 1561
Const dDesignMode As Double = 1605
Const dAssignMacro As Double = 859

--------------------------------------------------------------------------------\
-------------------------

Sub DisV()
Application.VBE.MainWindow.Visible = False '// Close ALL VBE Windows 1st!
CmdControl dCustomize, False '// Customize
CmdControl dVbEditor, False '// &Visual Basic Editor
CmdControl dMacros, False '// Macros...
CmdControl dRecordNewMacro, False '// Record New Macro...
CmdControl dViewCode, False '// View Code
CmdControl dDesignMode, False '// Design Mode
CmdControl dAssignMacro, False '// Assig&n Macro...
Application.OnDoubleClick = "Dummy"
Application.CommandBars("ToolBar List").Enabled = False
Application.OnKey "%{F11}", "Dummy"
End Sub

--------------------------------------------------------------------------------\
-------------------------

Sub EnaV()
CmdControl dCustomize, True '// Customize
CmdControl dVbEditor, True '// &Visual Basic Editor
CmdControl dMacros, True '// Macros...
CmdControl dRecordNewMacro, True '// Record New Macro...
CmdControl dViewCode, True '// View Code
CmdControl dDesignMode, True '// Design Mode
CmdControl dAssignMacro, True '// Assig&n Macro...
Application.OnDoubleClick = vbNullString
Application.CommandBars("ToolBar List").Enabled = True
Application.OnKey "%{F11}"
End Sub

--------------------------------------------------------------------------------\
-------------------------

Sub Dummy()
'// NoGo, leave blank OR Display a message eg.
10 'MsgBox "Sorry this command is NOT available", vbCritical
End Sub

'===============================================================================\
================================================
'-The following code is useful if you don't want a user to be able to edit the
'-Excel's main menu/commandbar by right clicking on it.
'===============================================================================\
================================================
'Purpose : Enables or disables Excel's main menu commandbar
'Inputs : [bEnable] If True enables the Excel's right click
menu, else disables it
'Outputs : N/A
'Notes :
'===============================================================================\
================================================
Function CommandBarRightClick(Optional bEnable As Boolean = False) As Boolean
On Error GoTo ErrFailed
CommandBars("toolbar List").Enabled = bEnable
If Not bEnable Then
CommandBars("toolbar List").Delete
CommandBarRightClick = False
Else
CommandBars("toolbar List").Reset
CommandBarRightClick = True
End If
Exit Function
ErrFailed:
Debug.Print "Error in CommandBarRightClick: " & Err.Description
CommandBarRightClick = False
End Function

--------------------------------------------------------------------------------\
-------------------------
Do this upon starting(opening) the Excel program such as in Private Sub
Workbook_Open()
--------------------------------------------------------------------------------\
-------------
Call DisV
Call CommandBarRightClick(False)

Do this upon exiting(closing) the Excel programPrivate Sub Workbook_Close()
--------------------------------------------------------------------------------\
-------------
Call EnaV
Call CommandBarRightClick(True)

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on How to password protect a worksheet Or get search suggestion and latest updates.


Tagged: