disable right mouse click

R

Rolf Bambey

Hi,
I want to disable the right mouse click on cells and the
sheet tab. Or better I want to get rid of the context
menu. Users of the workbook now are able to view the VBA
code and are able to rename the sheet name. The VBA code
is protected of course but the menu do not have to appear.
Please give me advise, thanks.

Rolf
 
J

JON-JON

To disable right click on cell use beforeright click event. In thisworkbook
code paste the code below.

Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target
As Range, Cancel As Boolean)
MsgBox "Not allowed"
Cancel = True
End Sub

To avoid changing the sheet name I suggest tools>protection>protect workbook

Hope this could help

Jon-jon
 
J

JON-JON

Hello pal,

I use this code when I got similar problem like yours. The first code will
clear your xl with the commandbar when your workbook activate while the
second will reverse it when your workbook is deactivated. I suggest that
you make a similar code that you will assign to a short-cut key that you may
use in case any of the event will not fire. This will happen if you have in
your code that could turn off enable events and not turning it on again.


Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.ScreenUpdating = False
For Each bar In Application.CommandBars
bar.Enabled = False
Next bar
Application.ScreenUpdating = True
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.ScreenUpdating = False
For Each bar In Application.CommandBars
bar.Enabled = True
Next bar
End If
Application.ScreenUpdating = True
End Sub

Hope this could help

Jon-jon
 
G

GB

Thanks, that's v helpful.

Geoff


JON-JON said:
Hello pal,

I use this code when I got similar problem like yours. The first code will
clear your xl with the commandbar when your workbook activate while the
second will reverse it when your workbook is deactivated. I suggest that
you make a similar code that you will assign to a short-cut key that you may
use in case any of the event will not fire. This will happen if you have in
your code that could turn off enable events and not turning it on again.


Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.ScreenUpdating = False
For Each bar In Application.CommandBars
bar.Enabled = False
Next bar
Application.ScreenUpdating = True
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.ScreenUpdating = False
For Each bar In Application.CommandBars
bar.Enabled = True
Next bar
End If
Application.ScreenUpdating = True
End Sub

Hope this could help

Jon-jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top