PC Review


Reply
Thread Tools Rate Thread

Before right click:

 
 
Steven
Guest
Posts: n/a
 
      26th Apr 2010
I have this as the first lines of code under an open workbook in it's:

This Workbook
Apps
Private Sub App_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As
Range, Cancel As Boolean)

---code---
If ActiveSheet.ProtectContents = True And ActiveCell.Locked = True Then
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = False
End With
Else
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = True
End With
End If


It always will return True no matter if the workbook is protected or not.
But if I use the code above on a right click menu custom item after the item
is clicked then it correctly identifies if the sheet is protected or not.

What am I doing wrong here?

Thank you for your help.

Steven

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      26th Apr 2010
I'm not sure what is returning True (.item(2).enabled???).

But this worked ok for me:

Option Explicit
Public WithEvents App As Excel.Application
Private Sub Workbook_Open()
Set App = Application
End Sub
Private Sub Workbook_Close()
Set App = Nothing
End Sub
Private Sub App_SheetBeforeRightClick(ByVal Sh As Object, _
ByVal Target As Range, Cancel As Boolean)

If Sh.ProtectContents = True _
And Target.Cells(1).Locked = True Then
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = False
End With
Else
With Application.CommandBars("Cell").Controls
.Item(2).Enabled = True
End With
End If
End Sub

(I had all the code in the ThisWorkbook module.)

Since excel passes the sheet (as Sh) and the range (as Target), I'd use them.

Steven wrote:
>
> I have this as the first lines of code under an open workbook in it's:
>
> This Workbook
> Apps
> Private Sub App_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As
> Range, Cancel As Boolean)
>
> ---code---
> If ActiveSheet.ProtectContents = True And ActiveCell.Locked = True Then
> With Application.CommandBars("Cell").Controls
> .Item(2).Enabled = False
> End With
> Else
> With Application.CommandBars("Cell").Controls
> .Item(2).Enabled = True
> End With
> End If
>
> It always will return True no matter if the workbook is protected or not.
> But if I use the code above on a right click menu custom item after the item
> is clicked then it correctly identifies if the sheet is protected or not.
>
> What am I doing wrong here?
>
> Thank you for your help.
>
> Steven


--

Dave Peterson
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File explorer hangs when right-click, ctrl-c, shift-delete, double-click =?Utf-8?B?RG91Zw==?= Windows XP Networking 1 9th Oct 2010 07:46 AM
PowerPoint Movie Plays After Click, Back-Click then Click Longhorn1955 Microsoft Excel Crashes 0 6th Apr 2010 06:27 AM
very very very slow boot: click, click, whirrrr, click, click, whi =?Utf-8?B?RGF2aWQgUy4gR29sZGZhcmI=?= Windows XP Performance 2 4th Apr 2006 03:58 PM
the keyboard key that holds down right-click. was "accessibility and rite-click to left-click robertssubscriptions@hotmail.com Windows XP Accessibility 4 25th Feb 2006 10:19 PM
System pauses for ages when click or right-click properties on large files news.plus.net Microsoft Windows 2000 File System 4 24th Jan 2004 12:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:59 AM.